Announcement Announcement Module
Collapse
No announcement yet.
Command not clear after a successful action ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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

      Comment


      • #4
        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.

        Comment


        • #5
          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

          Comment


          • #6
            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 :-)

            Comment


            • #7
              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

              Comment


              • #8
                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.

                Comment


                • #9
                  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 ?

                  Comment


                  • #10
                    ... to help reduce the number of state definitions.

                    Comment

                    Working...
                    X