Announcement Announcement Module
Collapse
No announcement yet.
Spring Web Flow 2: problem to save multiple models with one view Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Web Flow 2: problem to save multiple models with one view

    Hi everyone,

    I have a form "mandatorydata-change.jsp" where the contact data (name, first name, ...) and the address of the user data must be specified. The contact data have his own table and the address data have his own table, so two different tables for a view.
    Now I want to save by Spring WebFlow 2 the contact data and address data of the user, each in its own table: "User"and "Useraddress".

    The problem now is, i can't save data from TWO models in ONE view with Spring WebFlow 2.

    Please can someone me help?

    Thanks, Lukem

  • #2
    Hi Lukem,

    The most obvious solution that comes to mind is to wrap the contact and address in a single object, which is then exposed to your flow. This especially makes sense if you're always dealing with the contact and address in lockstep.

    There's nothing that says that the exact form object you're using must be saved as is - you could just as easily unwrap the contact and address and save each independently in the web flow action associated with form submission.

    Hope this helps
    - Don

    Comment


    • #3
      Hi dbrinker,

      Thank you for your answer...

      I have defined the address user flow as a subflow (child-flow) in mandatorydata-change flow (parent-flow).
      Here are the code:
      In JSP (mandatorydata-change.jsp):
      Code:
      ...
      <form:form method="post" modelAttribute="myAccount"> 
      ...
      <form:form method="post" modelAttribute="useraddress">
      ...
      </form:form>
      ...
      </form:form>
      In parent-flow:
      Code:
      ...
      	<var name="myAccount" class="mmv.pojos.User" />
      	<var name="useraddress" class="mmv.pojos.Useraddress" />
      ...
      <on-start>
      		<evaluate expression="userService.getUserIdByUsername(currentUser.name)" result="flowScope.userId" />
      		<evaluate expression="userService.getUserById(flowScope.userId)" result="myAccount" />
      	</on-start>
      ...
      <view-state id="Mymmvmandatorydatachange" model="myAccount">
      		<transition on="saveUserAddressData" to="MymmvUserAddress" />
      		<transition on="saveData" to="MymmvMandatoryDataChange" />
      	</view-state>
      ...
      <subflow-state id="MymmvUserAddress" subflow="myMMVuseraddress">   
      		<input name="useraddress" value="useraddress"/>
              <transition on="UseraddressEnd" to="Mymmvmandatorydatachange"/>
       	</subflow-state>
      ...
      In child-flow:
      Code:
      ...
      <var name="useraddress" class="mmv.pojos.Useraddress" /> 
      			
      	<action-state id="UseraddressSave">
      		<evaluate expression="userService.persistUseraddress(useraddress)" />
      		<transition on="success" to="UseraddressEnd">
      			<set name="flashScope.saveDataSuccess" value="true"/>
      		</transition>
      		<transition on="error" to="UseraddressEnd" />
      	</action-state>
      	
      	<end-state id="UseraddressEnd" commit="true" view="MymmvMandatoryData" />
      ...
      The problem now is that the user address data can not be saved. And this is really logical, because the modelAttribute "useraddress " in JSP was not passed to the model in parent flow (<view-state id="Mymmvmandatorydatachange" model="myAccount"> ...</ view-state>) . There was only the modelAttribute "myAccount".
      Do you know how in a view-state can pass two models?
      Thank you for your help.
      Lukem
      Last edited by Lukem; Feb 14th, 2011, 08:51 AM.

      Comment

      Working...
      X