Results 1 to 10 of 10

Thread: Command not clear after a successful action ?

  1. #1
    Join Date
    Sep 2004
    Posts
    133

    Default Command not clear after a successful action ?

    Hi ,

    If develope with spring original MVC , command object always clear after each successful action , with SWF it is not the case , why ?
    With this behaviour , l alway got what l typed b4 in my input box if my formView and successView are the same , any method to avoid these ?

    moon

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Well, if the form object is put in flow scope, it'll stay there for the life of the flow. If it's in request scope, a new one will be created on each request, which sounds like what you want here.

    SimpleFormController in Spring MVC is a hard-coded web flow for simple one page forms. Web flow, on the other hand, is a a generic web flow system where you fully define what the flow does.

    Thus, as part of its workflow, SFC puts the command object in the session after get but before submit, removing it post submit to detect duplicate submissions.

    Web flows use flow storage for caching objects between requests, and objects in flow scope are cleaned up automatically when the flow ends. If you want to clean them up before that, you need to do it manually, or just not put them in flow scope to begin with.
    Keith Donald
    Core Spring Development Team

  3. #3
    Join Date
    Sep 2004
    Posts
    133

    Default

    Those 7 examples in SWF don't have the problem of mine , because their successful pages are a different pages , what if my formview and successview are the same ? it is a commmon scenario that many flow does not have end-state, for example,

    Code:
    <webflow id="PublisherCRUDFlow" start-state="setupForm">
    	<action-state id="setupForm">
    		<action name="prepare" bean="publisherCRUDAction"/>
    		<transition on="prepare.success" to="formView"/>
    	</action-state>
    
    	<view-state id="formView" view="publisherCR">
    		<transition on="add" to="bindAndValidate.SaveForm"/>
                    <transition on="search" to="Search"/>
    	</view-state>
    
    	<action-state id="bindAndValidate.SaveForm">
    	        <action bean="publisherCRUDAction" method="bindAndValidate"/>
    		<transition on="success" to="Save"/>
    		<transition on="error" to="formView"/>
    	</action-state>
    
    	<action-state id="Save">
    	        <action name="Save" bean="publisherCRUDAction"/>
    		<transition on="Save.success" to="formView"/>
    		<transition on="Save.error" to="formView"/>
    	</action-state>
    	
    	<view-state id="formView1" view="publisherCR">
    		<transition on="add" to="bindAndValidate.SaveForm"/>
                    <transition on="search" to="Search"/>
    	</view-state>
    
    	<action-state id="Search">
    	        <action name="Search" bean="publisherCRUDAction"/>
    		<transition on="Search.success" to="formView"/>
    		<transition on="Search.error" to="formView"/>
    	</action-state>
    
    </webflow>
    Obviously , l cannot use flow scope here , then l have only one choice --> l need to clean them up manually . So two methods l can think of , 1. clear it in jsp using <c:remove> ? no , what if error occur ? then my publisherName cannot put back to the inputbox , 2. clear in controller , doesn't it look ugly in controller if this automatic clear mechanism not supported ?

    moon

  4. #4
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    First off, flow actions are NOT controllers. They're actions (commands would be another OK term, but controller is the wrong term -- getting picky, the flow itself is the controller.)

    Removing an attribute from java code is easy:
    Code:
    getFlowScope&#40;&#41;.removeAttribute&#40;"myAttribute&#41;";
    A good solution would be to transition to a form setup action state before rendering the view each time, and have it do whatever setup logic you need--removing/resetting whatever you want. That's pretty easy. Eventually we will build a view setup action from within the ViewState itself, then it'll be even easier.
    Keith Donald
    Core Spring Development Team

  5. #5
    Join Date
    Sep 2004
    Posts
    133

    Default

    kdonald , this is funny , u can change the context of the post ? hahaha...
    it is different from 5 mins ago that l saw it ...hihihi

    if there is no automatic mechanism ,
    Code:
    getFlowScope&#40;&#41;.removeAttribute&#40;"myAttribute&#41;";
    will exist in all the Actions (since u considered a flow is a controller , ) , because actions alway success ( that is what we want) ....

    moon

  6. #6
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Well, if that's the case then, I would NOT store your formObject in "flowScope"--use the default request scope type instead. Then ensure you always route through the setup action state before going back to the form view state, as recommended in the FormAction documentation. That way you'll get a fresh form object instance created automatically before each view state is entered.

    In any case, what you stated in your last post is not true. You could always have a action state that does the manual remove, and route through it--centralizing that logic. That's the power of webflow--if you're duplicating stuff accross your actions you're using the system wrong.

    So just follow my recommendation above. :-)

    Yes, you can edit posts :-)
    Keith Donald
    Core Spring Development Team

  7. #7
    Join Date
    Sep 2004
    Posts
    133

    Default

    Actually l did not use "FlowScope" , l used "RequestScope" all.

    u mean that l have to do it
    Code:
    	<action-state id="Save">
    	        <action name="Save" bean="publisherCRUDAction"/>
    		<transition on="Save.success" to="setupForm"/>
    		<transition on="Save.error" to="formView"/>
    	</action-state>
    instead of
    Code:
    	<action-state id="Save">
    	        <action name="Save" bean="publisherCRUDAction"/>
    		<transition on="Save.success" to="formView"/>
    		<transition on="Save.error" to="formView"/>
    	</action-state>
    ?
    l tried it , done !

    u mean l can change my post after l posted it ? how ? hihihi ....

    moon

  8. #8
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Yes, you got it -- again, we'll likely add first class support for such setup logic in the view state in the future.

    just click on the post and hit the edit button. you can only edit ur own posts.
    Keith Donald
    Core Spring Development Team

  9. #9
    Join Date
    Sep 2004
    Posts
    133

    Default

    we'll likely add first class support for such setup logic in the view state in the future
    you add this because you wanna clear command or other design consideration ?

  10. #10
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    ... to help reduce the number of state definitions.
    Keith Donald
    Core Spring Development Team

Similar Threads

  1. Exit action from view state
    By pglezen in forum Web Flow
    Replies: 5
    Last Post: Oct 7th, 2005, 02:23 PM
  2. autowire for struts action
    By houyunf in forum Web
    Replies: 2
    Last Post: Sep 2nd, 2005, 12:33 PM
  3. Replies: 4
    Last Post: Aug 1st, 2005, 03:45 PM
  4. Question about Action
    By snpe in forum Swing
    Replies: 3
    Last Post: Nov 8th, 2004, 08:58 AM
  5. Form model with database action
    By snpe in forum Swing
    Replies: 3
    Last Post: Nov 2nd, 2004, 08:45 AM

Posting Permissions

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