Spring Flow:从Main WebFlow和Subflow之间来回传递对象

use*_*072 2 java spring-webflow

我从主流中调用子流.我已经能够ShareHolderProfile从MainFlow 将对象传递给SubFlow.但是,我不确定这个相同的对象是否没有被传递回MainFlow,或者我在JSP中没有正确访问它.我是这样做的.

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>
Run Code Online (Sandbox Code Playgroud)

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" />
Run Code Online (Sandbox Code Playgroud)

现在,在大多数情况下,应用程序中的流程工作正常.但是,问题是我一直试图从我的一个jsp中的acctProfile访问一些属性(Member变量).像 - acctProfile.FirstName

但是,我无法做到这一点.acctProfile对象是不是从subFlow传递到Mainflow,还是我在JSP中错误地使用它.请指教.

提前致谢

Alo*_*bar 7

2件事:

  1. 声明输入(或输出)参数时,请确保添加要传递的对象的类型(这可能是您无法访问actProfile属性的原因).例如,如果actProfile属于类型com.mycompany.ActProfile,那么您应该这样声明它:

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

    您需要在MainFlow.xml SubFlow.xml中执行此操作.

  2. 为了重新访问actProfile(从SubFlow到MainFlow),您应该将它声明为从SubFlow到MainFlow的输出变量.这就是它的完成方式:

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"/>
Run Code Online (Sandbox Code Playgroud)

同样,在SubFlow.xml中:

<end-state id="finish" >
 <output name="actProfile" value="actProfile" type="com.mycompany.AcctProfile" />
</end-state>
Run Code Online (Sandbox Code Playgroud)