Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC, Spring Web Flow, formObject help Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC, Spring Web Flow, formObject help

    Hi,
    I am trying to use Spring MVC, Spring Web Flow, formObject. I have posted below my flow.xml, beans.xml and action class. I need to be able to pass the form object to my action method but I get null on my action method. Please help.
    I do not want in this form
    public Event getDoctorOrdersInfo(RequestContext context) throws Exception {
    I like to be able to do this form
    public Event getDoctorOrdersInfo(CustomerDoctorOrders doctorOrders) throws Exception {

    -----------flow.xml ----------------
    <start-state idref="addDoctorOrders"/>

    <view-state id="addDoctorOrders" view="customer/addDoctorOrdersFlow">
    <transition on="submit" to="getDoctorOrdersInfo"/>
    <transition on="cancel" to="submitEndState"/>
    </view-state>

    <view-state id="getDoctorOrdersInfo" view="customer/customerDoctorOrders">
    <entry-actions>
    <action bean="formActionDoctorOrders" method="setupForm"/>
    </entry-actions>
    <transition on="submit" to="saveDoctorOrdersInfo"/>
    <transition on="cancel" to="cancelEndState"/>
    </view-state>

    <action-state id="saveDoctorOrdersInfo">
    <bean-action bean="addDoctorOrdersActions" method="getDoctorOrdersInfo">
    <method-arguments>
    <argument expression="flowScope.doctorOrders"/>
    </method-arguments>
    <method-result name="doctorOrders"/>
    </bean-action>
    <transition on="success" to="getDoctorOrdersSupplyInfo"/>
    <transition on="error" to="errorPage"/>
    </action-state>

    <view-state id="getDoctorOrdersSupplyInfo" view="customer/customerDoctorOrdersSupply">
    <entry-actions>
    <action bean="formActionDoctorOrdersSupply" method="setupForm"/>
    </entry-actions>
    <transition on="submit" to="submitEndState"/>
    <transition on="cancel" to="cancelEndState"/>
    </view-state>


    ---------beans.xml------------------
    <bean id="formActionDoctorOrders" class="org.springframework.webflow.action.FormActi on">
    <property name="formObjectName" value="doctorOrders"/>
    <property name="formObjectClass" value="com.vahms.model.formobjects.CustomerDoctorO rders"/>
    <property name="formObjectScope" value="FLOW"/>
    <!--
    <property name="validator">
    <bean class="com.vahms.model.formobjects.CustomerDoctorO rdersValidator"/>
    </property>
    -->
    </bean>

    <bean id="addDoctorOrdersActions" class="com.vahms.webapp.action.flow.AddDoctorOrder sActions"/>

    ------------action class with form object method ------------------

    public class AddDoctorOrdersActions {
    public void getDoctorOrdersInfo(CustomerDoctorOrders doctorOrders) throws Exception {

    log.debug(userName + ":" + "getDoctorOrdersInfo(), printing sample form attribute/s: " + doctorOrders.getDateToCustomer() + " - " + doctorOrders.getDateSent());
    }

    -----------------------------------------------------------------------

  • #2
    Your code / XML looks okay at first sight. You're not getting any errors?

    Erwin

    Comment


    • #3
      my error

      With above xml conf I get the below error

      org.springframework.web.util.NestedServletExceptio n: Request processing failed; nested exception is org.springframework.webflow.engine.ActionExecution Exception: Exception thrown executing [AnnotatedAction@6f513 targetAction = org.springframework.webflow.action.LocalBeanInvoki ngAction@10285d8, attributes = map[[empty]]] in state 'saveDoctorOrdersInfo' of flow 'flow-AddDoctorOrders' -- action execution attributes were 'map[[empty]]'; nested exception is org.springframework.binding.method.MethodInvocatio nException: Unable to invoke method [MethodSignature@4e68fb methodName = 'getDoctorOrdersInfo', parameters = [[Parameter@9b1ac type = [null], name = flowScope.doctorOrders]]] with arguments array[com.vahms.model.formobjects.CustomerDoctorOrders@d 9c6e2]; nested exception is java.lang.reflect.InvocationTargetException
      Caused by: org.springframework.webflow.engine.ActionExecution Exception: Exception thrown executing [AnnotatedAction@6f513 targetAction = org.springframework.webflow.action.LocalBeanInvoki ngAction@10285d8, attributes = map[[empty]]] in state 'saveDoctorOrdersInfo' of flow 'flow-AddDoctorOrders' -- action execution attributes were 'map[[empty]]'; nested exception is org.springframework.binding.method.MethodInvocatio nException: Unable to invoke method [MethodSignature@4e68fb methodName = 'getDoctorOrdersInfo', parameters = [[Parameter@9b1ac type = [null], name = flowScope.doctorOrders]]] with arguments array[com.vahms.model.formobjects.CustomerDoctorOrders@d 9c6e2]; nested exception is java.lang.reflect.InvocationTargetException
      Caused by: org.springframework.binding.method.MethodInvocatio nException: Unable to invoke method [MethodSignature@4e68fb methodName = 'getDoctorOrdersInfo', parameters = [[Parameter@9b1ac type = [null], name = flowScope.doctorOrders]]] with arguments array[com.vahms.model.formobjects.CustomerDoctorOrders@d 9c6e2]; nested exception is java.lang.reflect.InvocationTargetException
      Caused by: java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.springframework.binding.method.MethodInvoker.i nvoke(MethodInvoker.java:96)
      at org.springframework.webflow.action.AbstractBeanInv okingAction.doExecute(AbstractBeanInvokingAction.j ava:132)



      I also have this xml file configuration which starts the flow(I am developing with AppFuse)
      -----------------------------
      <bean name="flowRegistry-AddDoctorOrders" class="org.springframework.webflow.registry.XmlFlo wRegistryFactoryBean">
      <property name="flowLocations">
      <list>
      <value>/WEB-INF/flows/flow-AddDoctorOrders.xml</value>
      </list>
      </property>
      </bean>
      <flow:registry id="flowRegistry-AddDoctorOrders">
      <flow:location path="/WEB-INF/flows/flow-AddDoctorOrders.xml"/>
      </flow:registry>
      <flow:executor id="flowExecutor-AddDoctorOrders" registry-ref="flowRegistry-AddDoctorOrders">
      <flow:execution-attributes>
      <flow:alwaysRedirectOnPause value="true"/>
      </flow:execution-attributes>
      </flow:executor>
      <bean id="addDoctorOrdersFlowController" class="org.springframework.webflow.executor.mvc.Fl owController">
      <property name="flowExecutor" ref="flowExecutor-AddDoctorOrders"/>
      <property name="defaultFlowId" value="flow-AddDoctorOrders"/>
      </bean>
      ------------------------------

      Comment


      • #4
        MethodInvocatio nException: Unable to invoke method [MethodSignature@4e68fb methodName = 'getDoctorOrdersInfo', parameters = [[Parameter@9b1ac type = [null], name = flowScope.doctorOrders]]] with arguments array[com.vahms.model.formobjects.CustomerDoctorOrders@d 9c6e2]; nested exception is java.lang.reflect.InvocationTargetException
        From this exception I would say your getDoctorOrdersInfo() method is called correctly with the com.vahms.model.formobjects.CustomerDoctorOrders@d 9c6e2 object as argument, but that the method throws an exception internally (hence the TargetInvocationException).

        Erwin
        Last edited by klr8; Mar 31st, 2007, 02:27 AM.

        Comment


        • #5
          I have done some changes/cleaning on my application and it seem like works fine. But I have a question;
          if I do
          VERSION1:
          1) extend FormAction and getting object with getFormObject(context);
          public class AddObjectDoctorOrdersActions extends FormAction {
          private final Log log = LogFactory.getLog(AddObjectDoctorOrdersActions.cla ss);
          public Event getDoctorOrdersInfo(RequestContext context) throws Exception {
          DoctorOrders doctorOrders = (DoctorOrders)getFormObject(context);
          log.debug(userName + ":" + "RCOgetDoctorOrdersInfo(), printing sample form attribute/s: " + doctorOrders.getDateToCustomer() + " - " + doctorOrders.getDateSent());
          return success();
          }
          }
          2)
          <bean id="addObjectDoctorOrdersActions" class="com.vahms.webapp.action.flow.AddObjectDocto rOrdersActions">
          <property name="formObjectClass" value="com.vahms.model.formobjects.DoctorOrders"/>
          </bean>
          3)
          <action-state id="saveDoctorOrdersInfo">
          <action bean="addObjectDoctorOrdersActions" method="getDoctorOrdersInfo"/>
          <transition on="success" to="getDoctorOrdersSupplyInfo"/>
          <transition on="error" to="errorPage"/>
          </action-state>

          works fine

          and if I do
          VERSION2:
          1) not extending anything and getting form object by passing to method
          public class AddObjectDoctorOrdersActions {
          private final Log log = LogFactory.getLog(AddObjectDoctorOrdersActions.cla ss);
          public void getDoctorOrdersInfo(DoctorOrders doctorOrders) throws Exception {
          try {
          log.debug(userName + ":" + "OgetDoctorOrdersInfo(), printing sample form attribute/s: " + doctorOrders.getDateToCustomer() + " - " + doctorOrders.getDateSent());
          } catch (Exception e) {
          log.debug(userName + ":" + "OgetDoctorOrdersInfo(), Exception : " + e.getMessage());
          }
          }
          }
          2)
          <bean id="addObjectDoctorOrdersActions" class="com.vahms.webapp.action.flow.AddObjectDocto rOrdersActions">
          <!-- <property name="formObjectClass" value="com.vahms.model.formobjects.DoctorOrders"/> -->
          </bean>
          3)
          <action-state id="saveDoctorOrdersInfo">
          <bean-action bean="addObjectDoctorOrdersActions" method="getDoctorOrdersInfo">
          <method-arguments>
          <argument expression="flowScope.doctorOrders"/>
          </method-arguments>
          </bean-action>
          <transition on="success" to="getDoctorOrdersSupplyInfo"/>
          <transition on="error" to="errorPage"/>
          </action-state>

          works fine too.
          but which is better?
          what is pros and cons?
          VERSION1 returns EVENT and VERSION2 returns void (good or bad)?
          thanks for help.

          Comment


          • #6
            I prefer VERSION2, which has the advantage of having less direct Java code dependencies on SWF. Also, for a simple direct method invocation like you have here VERSION2 is clean and readible.

            However, some people would probably prefer VERSION1 because it put's the code where it really belongs: in Java.

            Erwin

            Comment


            • #7
              I'm a VERSION 2 user but, sometimes, I miss the simplicity of Version 1.

              Comment

              Working...
              X