I've managed to get what I want when mapping with inheritance like this:
ThisClassShouldntExist
- freeFlowMsg
- errorMsg
BaseForm extends ThisClassShouldntExist
- function
- subFunction
SpecificForm extends BaseForm
- address
My binding.xml:
<binding>
<mapping class="com.struts.form.ThisClassShouldntExist" abstract="true">
<value name="free-flow-message" field="freeFlowMessage" />
<value name="error-msg" field="errorMessage" />
</mapping>
<mapping class="com.struts.form.BaseForm" abstract="true">
<value name="prog-name" field="function" />
<value name="sub-prog-name" field="subFunction" />
</mapping>
<mapping name="cngaddress" class="com.struts.form.AddressDisplayForm">
<structure name="header">
<structure map-as="com.struts.form.BaseForm" usage="optional" />
</structure>
<value name="address" field="addressline1" usage="optional"/>
<structure name="FOOTER">
<structure map-as="com.struts.form.ThisClassShouldntExist" usage="optional" />
</structure>
</mapping>
</binding>
A sample data:
<?xml version="1.0" encoding="UTF-8"?>
<cngaddress>
<header>
<prog-name>prog-name</prog-name>
<sub-prog-name>sub-prog-name</sub-prog-name>
</header>
<address>address</address>
<FOOTER>
<free-flow-message>free-flow-message</free-flow-message>
<error-msg>error-msg</error-msg>
</FOOTER>
</cngaddress>
So, the bottom line is that I need to "split" the output of the class BaseForm into 2 different part of the XML output. First part goes into <header>
, second into <footer>
, but also I want to avoid the inheritance just to comply with JibX.
I tried doing something like this but didn't work:
<structure name="FOOTER">
<structure field="aFieldFromSuperClassBaseForm" map-as="com.struts.form.ThisClassShouldntExist" usage="optional" />
</structure>
Also tried to define 2 <mapping>
in the same binding for the same class, but of course it wouldn't work.