Spring Flow: Pass object back and forth from between Main WebFlow and Subflow

谁都会走 提交于 2020-01-04 05:15:10

问题


I am calling a subflow from a main flow. I have been able to pass an object ShareHolderProfile to the SubFlow from the MainFlow. However, I am not sure if this same object is not being passed back to the MainFlow or I am not properly accessing it in my JSP. Here is how I am doing it.

MainFlow.xml

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"
start-state="retriveAccount">

    <var name="acctProfile" class="com.abc.xyz.account.ShareHolderProfile"/>

    <view-state id="retriveAccount" view="AccountView">
        <transition on="Success" to="createAccountSubFlow"/>
    </view-state>

    <subflow-state id="createAccountSubFlow" subflow="createAccountSubFlow">
        <input name="acctProfile" value="acctProfile"/>     
        <transition on="finish" to="showAlternateRoute"/>
    </subflow-state>    

    <view-state id="showAlternateRoute" view="showAlternateView" model="acctProfile">
        <on-entry>
            <evaluate someExpression result="viewScope.SomeValue"/>
        </on-entry> 
        <transition on="viewAction" to="accountDetails"/>       
    </view-state>

SubFlow.xml

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow  
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"
start-state="showAccount">

    <input name="acctProfile" />    

    <view-state id="showAccount" view="randomView" model="acctProfile">
        <on-entry>
            <evaluate expression="SomExpression"/>  
        </on-entry>  
        <transition on="SomeEvent" to="NextState"/>
    </view-state>

    <view-state id="NextState" view="SomeRandomView" model="acctProfile">
         <on-entry>
             <evaluate expression="controller.Method(acctProfile)" result="viewScope.profileForm"/>
         </on-entry>
         <transition on="viewResult" to="finish"/>
    </view-state>

    <end-state id="finish" />

Now, for the most part, the flows in the applications works fine. However, the problem is that I have been trying to access some attributes (Member variable) from acctProfile in one of my jsp . Something like - acctProfile.FirstName

However, I am not able to do this. Is the acctProfile object not being passes from the subFlow to Mainflow or am I using it incorrectly in the JSP. Please advise.

Thanks in advance


回答1:


2 things:

  1. When you declare an input (or output) parameter be sure to add the type of the object you are passing (this is probably why you can't access the attributes of actProfile). For instance if the actProfile is of class type com.mycompany.ActProfile, then you should declare it this way:

    <input name="acctProfile" value="actProfile" type="com.mycompany.ActProfile" />

    You need to do that both in your MainFlow.xml and SubFlow.xml.

  2. In order to access actProfile back (from the SubFlow to the MainFlow), you should declare it as an output variable from your SubFlow to your MainFlow. This is how it's done:

MainFlow.xml:

<subflow-state id="createAccountSubFlow" subflow="createAccountSubFlow">
    <input name="actProfile" value="actProfile" type="com.mycompany.ActProfile" />  
    <output name="actProfile" value="actProfile" type="com.mycompany.ActProfile" /> 
    <transition on="finish" to="showAlternateRoute"/>

Similarly, in SubFlow.xml:

<end-state id="finish" >
 <output name="actProfile" value="actProfile" type="com.mycompany.AcctProfile" />
</end-state>


来源:https://stackoverflow.com/questions/7885951/spring-flow-pass-object-back-and-forth-from-between-main-webflow-and-subflow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!