Announcement Announcement Module
Collapse
No announcement yet.
Calling method on Page Load using Webflow Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calling method on Page Load using Webflow

    Hi All,

    I have a basic doubt here,

    I want to call a method when my page loads using Spring Webflow.
    In Spring Webflow,when a page loads the first method that gets called is setupForm in FlowController if we specify teh below code in <view-state>
    Code:
    <render-actions>
    	<action bean="formAction" method="setupForm" />
    </render-actions>
    After this stage i am able to call any method, but according to my requirement i need to call a method before page loads and display the data.

    I tried putting it this way, but it does not work before <view-state>

    <start-actions>
    <action bean="formAction" method="setupForm" />
    <bean-action bean="myclass" method="myMethod">
    <method-result name="referenceData" />
    </bean-action>
    </start-actions>
    The error i get here is:

    nested exception is org.springframework.binding.method.InvalidMethodKe yException:Could not resolve method with key myMethod;
    Please give suggestions.

    Thanks in Advance,
    DeepEdward
    Last edited by DeepEdward; Feb 29th, 2008, 07:23 AM.

  • #2
    I'm not sure what you are trying to achive.

    What do you want your method to do that cant be done after or during setupForm.

    Damien

    Comment


    • #3
      Hi Damo,

      I need to fetch come values from the database and when the page loads, it must also be displayed in the page. Using Spring mvc it was quite simple to do as my controller was called on page load, but here (in webflow)i need to invoke the method during the flow.

      As am new to webflow, do gimme some idea and temme if i need to follow some other way.

      Thanks in Advance,
      DeepEdward

      Comment


      • #4
        Do you have bean with name "myclass" defined in your Spring application context? Another point to check is that if there is a method with name "myMethod" defined in your "myclass" bean's class?

        Comment


        • #5
          If i understand what you are trying to do it is quite easy.

          All you need it a view state and a form action e.g.

          <view-state id="userdetails" view="userdetails">
          <render-actions>
          <action bean="detailsFormAction" method="setupForm"/>
          <action bean="detailsFormAction" method="setupReferenceData"/>
          </render-actions>
          </view-state>


          <bean id="detailsFormAction" class="myClasses.DetailsFormAction">
          <property name="formObjectName"><value>details</value></property>
          <property name="formObjectClass" value="myClasses.FormObject"/>
          <property name="resourceProviderDelegate" </bean>

          When the view state is executed it calls setUpForm which creates your your formObject. The next method called is setUpReferenceData. This function can call onto DB to get the nesecarry values. From this function the FormObject can be populated. Your JSP page will subsequently bind to your form object and display the values.

          setUpReferenceData is a function you need to implement on your form action and can be called what ever you like e.g. it could be called loadFormData.


          Note: setUpForm is is not a function you need to write as it is already on FormAction which detailsFormAction should extend

          Comment


          • #6
            Thanks Damo for the reply,

            I got the thing working but I have been following a different way to achieve this.
            Could you please clarify some doubts i have to make my concept better:

            1. As you mentioned, detailsFormAction
            This must be a subclass of FormAction, so that I get the setupForm and get the formObject.

            2. If I have a number of drop-down list to be populated then I need to return a map and refer to the key(myList) in my jsp.

            map.put("myList", myService.getName());

            This does not work here in webflow bcoz I return a Map and it cannot interpret the key(myList) in the jsp page(it worked in spring web mvc), so for this am passing a list directly back to the flow-result,and it works.
            Is there a better way of doing this,certainly there must be, could you pls tell me how to solve this.


            3. What is resourceProviderDelegate that you mentioned


            Thanks in advance,
            DeepEdward

            Comment


            • #7
              1 - yeah DetailsFormAction needs to be a subclass of formAction

              2 - For my implmentations i put my lists directly into scope - I dont think there is an issue with this as the flow scope is managed properly i.e. gets emptied at the end of the flow unlike session scope

              3 - ignore the ResourceProviderDelage - that is something I have copied from one of my applications and is something i have implemented as a layer of abstraction to a web service that i call. I meant to remove it from my example - sorry if it has confused you

              Comment


              • #8
                What if i need to populate my page with 10 different drop-down lists.

                Don't you think that calling a different method to populate each list will increase the line of codes unnecessarily? Instead of that a Map could have been used,using it to populate all the lists in one go.

                Regards,
                DeepEdward
                Last edited by DeepEdward; Mar 4th, 2008, 04:01 AM.

                Comment

                Working...
                X