Announcement Announcement Module
Collapse
No announcement yet.
SWF: binding to model bean problem when going to previous view-state Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SWF: binding to model bean problem when going to previous view-state

    The Problem:
    I want to implement some kind of configuration wizard using web flow. In this wizard user can (counting from second page) go to next page of wizard or go back to previous, each page is a form page (with checkboxes, and other inputs). When I do the forwards, binding to the model bean works fine, but when I want to go to the previous state it looks like bean in model is cleared (checkboxes are not checked), on the other hand when I click the "Back" button in web browser model bean is not cleared (checkboxes are checked). I was searching Spring swf forum for some solution, I noticed that there was several posts with some similar problems, but they didn't help me. And there was one post on Keith Donald's blog: http://blog.springsource.com/2009/04...roject-update/ where in Redirect-after-post improvements part he wrote: "One of the most useful features of Web Flow is the redirect-after-post pattern just works, which is one critical prerequisite to good back button support with controlled navigation". But I don't know if it will do the case, because I don't want to implement back button functionality, in my case when you click "previous" button on form, I want to go to previous state with my data in model bean saved.
    Configuration:
    1) part of view-state configuration file (configurator-flow.xml):
    Code:
    	<on-start>
    		<evaluate expression="swfConfiguratorHandler.getLoggedEmployee()" result="flowScope.employee" result-type="Employee"/>
    		<evaluate expression="swfConfiguratorHandler.initConfiguratorDto()" result="flowScope.configuratorDto" result-type="ConfiguratorDTO"/>
    	</on-start>
    	
    	<view-state id="employerSelection" view="configurator/employer-selection" model="configuratorDto" >
    		<on-entry>
    			<evaluate expression="swfConfiguratorHandler.wrapZfsBenefitsForConfigurator()" result="flowScope.configuratorDto.zfsList" result-type="java.util.ArrayList" />
    			<evaluate expression="swfConfiguratorHandler.wrapEmployerBenefitsForConfigurator()" result="flowScope.configuratorDto.employerList" result-type="java.util.ArrayList" />
    		</on-entry>
    		<transition on="gotoEmployeeSelection" to="employeeSelection" />
    	</view-state>
    
    	<view-state id="employeeSelection" view="configurator/employee-selection" model="configuratorDto">
    		<on-entry>
    			<evaluate expression="swfConfiguratorHandler.wrapEmployeeBenefitsForConfigurator(configuratorDto.zfsList, configuratorDto.employerList)" result="flowScope.configuratorDto.employeeList" result-type="java.util.ArrayList" />
    		</on-entry>
    		<transition on="gotoBack" to="${flowScope.previousViewStateId}" bind="true"/>
    		<transition on="gotoSelectionSummary" to="selectionSummary" />
    	</view-state>
    2) part of view="configurator/employer-selection" from employerSelection view-state:
    Code:
    <form:form modelAttribute="configuratorDto" action="" method="POST">
      <c:forEach items="${configuratorDto.zfsList}" var="item" varStatus="i">
        <form:checkbox path="zfsList[${i.count-1}].checked"/>
      </c:forEach>
      
      <c:forEach items="${configuratorDto.employerList}" var="item" varStatus="i">
        <form:checkbox path="employerList[${i.count-1}].checked"/>
      </c:forEach>
    
      <input type="submit" name="_eventId_cancelConfigurator" value="Cancel"/>
      <input type="submit" name="_eventId_gotoEmployeeSelection" value="Next"/>
    </form:form>
    3)part of view configurator/employee-selection from employeeSelection" view-state:
    Code:
    <form:form modelAttribute="configuratorDto" action="" method="POST">
    
      <c:forEach items="${configuratorDto.employeeList}" var="item" varStatus="i">
        <form:checkbox path="employeeList[${i.count-1}].checked"/>
      </c:forEach>
      
      <input type="submit" name="_eventId_gotoBack" value="Previous"/>
      <input type="submit" name="_eventId_cancelConfigurator" value="Cancel"/>
      <input type="submit" name="_eventId_gotoSelectionSummary" value="Forward"/>
    </form:form>
    I'm using SWF 2.0.9 and Spring 2.5.6

    Thanks for any help

  • #2
    Solution

    There was mistake in my implementation, when I click "Previous" on view "configurator/employee-selection" of "emloyeeSelection" view-state then lists in configuratorDto (zfsList, and employerList) in <on-entry/> in "employerSelection" view-state were reinitiated, and thats because the bean was cleared (and the checkboxes were not checked). So the problem is solved now. (Lesson learned: If you're tired and sleepy - go to sleep - no programming).

    Comment

    Working...
    X