Results 1 to 4 of 4

Thread: Model duration just for form submission and save action

  1. #1
    Join Date
    Nov 2006
    Posts
    16

    Default Model duration just for form submission and save action

    I feel that I am not understanding something fundamental about Spring Web flow - and in particular how to set the scope of a model.

    What I want is for a model to last for the duration of form submission and the subsequent action which saves the object to the database.

    The user is then returned to the list of objects and if they choose to add another object they will presented with a brand new model.

    At the moment when the user adds another object he is presented with the values of the last used model.

    Please view the flow definition files and tell me what I'm missing.

    Code:
    <var class="onlineexpenses.domain.Vehicle" name="vehicle"/>
    	
    	<view-state id="manageVehicles" >
    		<on-entry>
    			<evaluate expression="personService.getVehiclesForUser(portalUser.collarNumber)" result="viewScope.userVehicles"></evaluate>
    		</on-entry>
    		<transition on="addVehicle" to="addVehicle" ></transition>
    		<transition on="cancel" to="cancel"  ></transition>
    	</view-state>
    	
    	<view-state id="addVehicle"  model="vehicle"  >
    		<binder>
    			<binding property="registration"/>
    			<binding property="description"/>
    			<binding property="friendlyName"/>
    			<binding property="cc"/>
    			<binding property="defaultVehicleFlag"/>
    		</binder>
    		<transition on="cancel" to="manageVehicles" bind="false" ></transition>
    		<transition on="save" to="saveVehicle" bind="true" ></transition>
    	</view-state>
    	
    	<action-state id="saveVehicle">
    		<on-entry>
    			<evaluate expression="portalUser.collarNumber" result="vehicle.person.collarNumber"></evaluate>
    		</on-entry>
    		<evaluate expression="personService.createVehicle(vehicle)"></evaluate>
    		<evaluate expression="vehicle.reset()"></evaluate>
    		<transition to="manageVehicles"></transition>
    	</action-state>
    	
    	<end-state id="cancel"/>
    		
    </flow>

  2. #2
    Join Date
    Nov 2008
    Posts
    742

    Default

    I think you'll find in the "saveVehicle" action-state that only your first evaluate is being executed, so vehicle is never reset. You'll need to either move the resetting of vehicle elsewhere (either another action-state, or, even better, on-entry of the "addVehicle" view-state), or tell SWF on which action (of the "set" or "evaluate" actions defined in the action state) to perform the transition. That involves putting a "name" attribute on the last action, and making the transition go on the named action. I'm fuzzy on the syntax, so I'll look for an example and link it when I'm able.

    That's one of the idiosyncrasies of SWF; all actions defined in transitions, on-entry, on-render, on-start, etc. get executed, but only the first action in an action state gets executed and drives the transition unless you do something special.

  3. #3
    Join Date
    Nov 2006
    Posts
    16

    Default Scoping Model Issue

    Hey

    Thanks for your reply and explanation of why the reset method was not invoked.

    That explains why that that method was not getting called. To be honest what I was really after was not having to use a reset method at all. I wanted the model to only last for the duration of the form submission and subsequent save action.

    I guess one way of doing this would be to create a separate subflow just for the addVehicle form submission and save action. This seems a bit of overkill just to get the model scoped correctly.

    I was wondering if there was another feature of spring workflow that I could use to scope the model as required.

    Once again thanks for your help.

  4. #4
    Join Date
    Nov 2008
    Posts
    742

    Default

    I'm afraid I won't be of much use here. I haven't explicitly used models in my flow. What I'll typically do is add a new bean to view-scope and initialize it (if it needs it) on-entry, bind values through JSF el, and then handle validation and any other cleanup in the transition.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •