Announcement Announcement Module
No announcement yet.
Spring Web Flow 2: problem to save multiple models with one view Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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


    • #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):
      <form:form method="post" modelAttribute="myAccount"> 
      <form:form method="post" modelAttribute="useraddress">
      In parent-flow:
      	<var name="myAccount" class="mmv.pojos.User" />
      	<var name="useraddress" class="mmv.pojos.Useraddress" />
      		<evaluate expression="userService.getUserIdByUsername(" result="flowScope.userId" />
      		<evaluate expression="userService.getUserById(flowScope.userId)" result="myAccount" />
      <view-state id="Mymmvmandatorydatachange" model="myAccount">
      		<transition on="saveUserAddressData" to="MymmvUserAddress" />
      		<transition on="saveData" to="MymmvMandatoryDataChange" />
      <subflow-state id="MymmvUserAddress" subflow="myMMVuseraddress">   
      		<input name="useraddress" value="useraddress"/>
              <transition on="UseraddressEnd" to="Mymmvmandatorydatachange"/>
      In child-flow:
      <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 on="error" to="UseraddressEnd" />
      	<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.
      Last edited by Lukem; Feb 14th, 2011, 08:51 AM.