[EMF Forms] Editing optional domain elements [message #1772811] |
Fri, 15 September 2017 14:51 |
Heiko Schaefer Messages: 7 Registered: April 2016 |
Junior Member |
|
|
Greetings Community,
I need to modify a domain model with optional elements. It looks like this:
<root>
<object>
<optionalAttribute>
<value>foo</value>
</optionalAttribute>
<mandatoryAttribute>
<value>bar</value>
</mandatoryAttribute>
</object>
</root>
I use EMF Forms (1.10.0) to edit the model and Resource.save with a default XMI factory to serialize the model.
The processing shall follow the following idea:
- The UI should only provide input fields for the "value" elements. There should be no controls to directly manipulate the parent elements.
- If the input field for optionalAttribute.value is not empty, I want the element optionalAttribute to be created within the model and later serialized with the corresponding value as seen above.
- If the input field is empty, I do not want the element to be created at all. At least it should not be serialized when the model is saved.
This means the result for an empty optionalAttribute.value should look like this:
<root>
<object>
<mandatoryAttribute>
<value>bar</value>
</mandatoryAttribute>
</object>
</root>
Unfortunately, I am observing the following serialization:
<root>
<object>
<optionalAttribute/>
<mandatoryAttribute>
<value>bar</value>
</mandatoryAttribute>
</object>
</root>
This is a problem, because the serialization result also needs to withstand an XML Schema-based validation to be processed in subsequent steps.
For a valid XML model each optionalAttribute needs a value. This means if there is no optionalAttribute.value, then there should be no optionalAttribute element at all.
I tried to explicitly remove such empty elements from the domain model, but EMF Forms listens to such changes and instantly creates a new element when resolving the feature path domain model reference.
Callstack when EMF Forms recreates the optional element:
VFeaturePathDomainModelReferenceImpl.resolve(EObject, boolean) line: 381
VFeaturePathDomainModelReferenceImpl.init(EObject) line: 475
SettingToControlExpandHelper.expandAndInitDMR(EObject, EMFFormsDomainExpander, EObject, EMFFormsViewContext) line: 65
SettingToControlExpandHelper.resolveDomainReferences(EObject, EObject, EMFFormsViewContext) line: 54
ViewModelListener.notifyChange(ModelChangeNotification) line: 105
ViewModelContextImpl$DomainModelContentAdapter.notifyChanged(Notification) line: 660
Possibly the model element is needed to bind it to the UI element.
I would be pleased if you have any hint how to solve the problem. Is there a way to edit optional elements with EMF Forms and have them created only if some inner fields are set?
With kind regards
Heiko
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03662 seconds