2011-10-25 33 views
2

我從主流調用子流。我已經能夠將對象ShareHolderProfile從MainFlow傳遞給SubFlow。但是,我不確定這個相同的對象是不是被傳回給MainFlow,或者我沒有在我的JSP中正確訪問它。這是我如何做的。Spring Flow:從主WebFlow和子流之間來回傳遞對象

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" /> 

現在,在大多數情況下,在應用程序的流程正常工作。然而,問題是我一直試圖從我的jsp中的一個acctProfile訪問一些屬性(成員變量)。類似於 - acctProfile.FirstName

但是,我無法做到這一點。 acctProfile對象是不是從subFlow傳遞給Mainflow,還是我在JSP中使用不正確?請指教。

在此先感謝

回答

7

兩兩件事:

  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"/> 

同樣,在SubFlow.xml:

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

這正是我的問題了。在我的情況下,還需要在子流的視圖狀態中添加模型屬性。 –