Modeling TrainStop as a boolean value property is not ideal here. I would try TrainStop element property with Outcome, etc. as value properties inside that nested model element.
BTW, I think what you are trying to do here with BooleanElementBinding is supported out of the box with @XmlValueBinding.mapExistenceToValue. In this example, @XmlValueBinding( path = "train-stop", mapExistenceToValue = "true" ) would have had the same effect as the custom binding.
- Konstantin
From: sapphire-dev-bounces@xxxxxxxxxxx [mailto:sapphire-dev-bounces@xxxxxxxxxxx] On Behalf Of Shenxue Zhou
Sent: Tuesday, August 30, 2011 1:28 PM
To: Sapphire project
Subject: [sapphire-dev] Removing empty element too aggressive
I have the following xml snippet to model:
<train-stop>
<outcome>asas</outcome>
<sequential>sadasd</sequential>
<skip>ser</skip>
<ignore>asdas</ignore>
</train-stop>
Here are "TrainStop" and the "Outcome" property:
@Type( base = Boolean.class )
@Label( standard = "train stop" )
@CustomXmlValueBinding( impl = BooleanElementBinding.class, params = "train-stop" )
@DefaultValue( text = "false" )
@Service( impl = TrainStopValidator.class )
@DependsOn("/TaskFlow/Train")
@Enablement( expr = "${parent().parent().BoundedTaskFlow}" )
ValueProperty PROP_TRAIN_STOP = new ValueProperty( TYPE, "TrainStop" );
Value<Boolean> isTrainStop();
void setTrainStop( String value );
void setTrainStop( Boolean value );
// *** Outcome ***
@XmlBinding( path = "train-stop/outcome")
@Label(standard = "outcome")
@Enablement( expr = "${ parent().parent().BoundedTaskFlow && TrainStop }" )
ValueProperty PROP_OUTCOME = new ValueProperty( TYPE, "Outcome" );
Value<String> getOutcome();
void setOutcome(String outcome);
Sequential, Skip and Ignore properties are modeled similiarly.
In UI, Outcome, Sequential, Skip and Ignore properties are only enabled when the TrainStop's value is "true".
If user edits "Outcome" property (or Sequential, Skip, Ignore properties) and then clears it, then <train-stop> element gets removed as well. This causes undesired result. The Train stop check box is unselected.
Any recommendation in how to fix this issue?