Announcement Announcement Module
Collapse
No announcement yet.
context.getModel() or other "session" data Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • context.getModel() or other "session" data

    What is the prefered way to store data in the webflow which should be accessed during the whole webflow? I know that there is the possibility to make a form with the scope FLOW but the information I have is completely unrelated to this form so I would like to store it independently.

    Think about a product name which is shown during a user registration wizard.
    It is loaded ones in the initial action and afterwards only displayed by the jsps. Normally I would put this as string in the session.

    Greetings,
    Markus

  • #2
    Easy:

    From your action code:

    Code:
    context.getFlowScope().setAttribute("productName", myProductName);

    Comment


    • #3
      I'm trying to figure out how to prepopulate a SELECT field for the first page of a flow. In the api for FormAction the last thing it says is
      Note that this action does not provide a referenceData() hook method similar to that of the SimpleFormController. If you need to setup reference data you should create a seperate state in your flow to do just that and make sure you pass through that state before showing the form view. Note that you can add the method that handles this reference data setup logic to a subclass of this class since this is a multi-action! Typically you would define an action execute method like

      public Event setupReferenceData(RequestContext context) throws Exception


      in that case.
      I don't understand how this setupReferenceData method will get called. I currently have
      Code:
      <webflow id="adminSignInFlow" start-state="adminSignInViewSetup">
          <action-state id="adminSignInViewSetup">
              <action bean="adminSignInViewSetup" method="setupForm" />
              <transition on="success" to="adminSignInView" />
          </action-state>
      Code:
      public class
      AdminSignInViewSetup extends FormAction &#123;
          public
          AdminSignInViewSetup&#40;&#41; &#123;
              setFormObjectClass&#40;AdminSignIn.class&#41;;
              setFormObjectName&#40;"adminSignIn"&#41;;
              setValidator&#40;new AdminSignInValidator&#40;&#41;&#41;;
              setFormObjectScope&#40;ScopeType.FLOW&#41;;
          &#125;
      &#125;
      (The ScopeType is there because I saw it somewhere and it looks cool. I'm not sure what it's doing. )

      (Finally let me don my hat of English grammar nanny nitpicker and point out some grammar and spelling errors. 1) It's sepArate, not sepErate. 2) Where you say "you need to setup" you're using the verb of SET UP, which is two words. You use SETUP when it's a noun, as in "you have a nice setup here".)

      Thanks again for all your help. I apologize for being such a dimbulb and needing to ask so many questions.

      Comment


      • #4
        Hmm, a lightbulb just went off. :idea: Could I have my first action-state transition to another action-state that has only one method, setupReferenceData, and then that transitions to my view? I.e., insert an action-state between my existing first action-state and the subsequent view. It seems like that would work but is there a better way?

        Comment


        • #5
          Yes, either that or just use a view state setup action. See the setup subelement of the view-state element.

          Keith

          Comment


          • #6


            Great, thanks!

            Comment


            • #7
              Thanks for catching those typos in the JavaDoc. I fixed them!

              Erwin

              Comment


              • #8
                Greetings!

                Will be needing to lookup reference data as well.

                What is a "view state setup action" or "setup subelement"? Also what would be the Java-base flow equivalent?

                Is that similar to doing the following:


                addViewState (PRODUCT_UNIT_OF_MEASURE_PAGE_ID, PRODUCT_UNIT_OF_MEASURE_PAGE,
                new Transition[] {on(beforeExecute (method ("referenceData", action (ProductFormAction.class))),PRODUCT_FULLFILLMENT_P AGE)});

                _CJ

                Comment


                • #9
                  &quot;setup&quot; subelement

                  If you know how to decode dtd files look at http://www.springframework.org/dtd/spring-webflow.dtd which comes from the doctype line at the top of your -flow.xml files.

                  Dtd files are a dark mystery to me so I'd love to see an example use of the setup subelement.

                  Comment


                  • #10
                    Originally posted by curtney
                    Greetings!... Also what would be the Java-base flow equivalent?
                    Also, what's the motivation for using a java based flow? I was puzzled about why the Spring Web Flow "Practical Guide" spent so much time explaining that.

                    Comment


                    • #11
                      For me, it is just a matter of preference, I hate having all of these xml configuration files laying around. However, it seems I might have to change to XML flows, since all flows are discussed and demonstrated in that way, at least in this Forum. Also, I have to admit they are more intuitive.

                      Perhaps all spriing web flow examples should have an equivalent Java-base flow.

                      _CJ

                      Comment


                      • #12
                        Here is an example of a view state with a setup action and a "bindAndValidate" on a transition. This kind of defines a "form state" (similar to the SimpleFormController) in a single SWF state:

                        Code:
                        	<view-state id="showMyForm" view="myForm">
                        		<setup bean="myFormAction" method="setupForm"/>
                        		<transition on="cancel" to="previousState"/>
                        		<transition on="submit" to="nextState">
                        			<action bean="myFormAction" method="bindAndValidate"/>
                        		</transition>
                        	</view-state>
                        Erwin

                        Comment


                        • #13
                          I've added an alternative flow definition to the BirthDate sample app to illustrate this kind of "form state". It's in birthDate-flow-simplefied.xml.

                          On a related note: there is actually a bug in PR3 that prevents the "form state" from working properly: you loose your bindAndValidate errors. I've already fixed the issue so if you grab a CVS snapshot everything is working again.

                          Erwin

                          Comment

                          Working...
                          X