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

发布于 2024-12-11 18:13:47 字数 2568 浏览 0 评论 0原文

我正在从主流程调用子流程。我已经能够将对象 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>

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 对象是否没有从子流传递到主流,或者我在 JSP 中错误地使用了它。请指教。

提前致谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盗心人 2024-12-18 18:13:48

两件事:

  1. 当您声明输入(或输出)参数时,请务必添加您传递的对象的类型(这可能就是您无法访问 actProfile 属性的原因)。例如,如果 actProfile 的类类型为 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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文