Spring Web Flow:如何将值从一个流传递到另一个流

发布于 2024-08-14 05:50:18 字数 3560 浏览 4 评论 0原文

我有一个使用 Spring Web Flow 的 Java Web 应用程序。

如何将值从一个流传递到另一个流?

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
    xmlns:c="http://java.sun.com/jsp/jstl/core" 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">

    <persistence-context />

    <var name="editBean" class="jp.co.anicom.domain.User" />
    <var name="deleteBean" class="jp.co.anicom.domain.User" />
    <var name="authorityBean" class="jp.co.anicom.domain.Authority" />


    <on-start>
        <set name="flowScope.username" value="requestParameters.username" />
    </on-start>

    <action-state id="queryAll">
        <evaluate expression="employeeAction.GetAuthority(flowScope.username)"
            result="authorityBean" />
        <transition to="editForm" />
    </action-state>

    <view-state id="editForm" model="editBean" view="../xhtml/framework/edit">
        <transition on="editButton" to="validateAccount" />
        <transition on="delete" to="getId" />
        <transition on="back" to="editSuccessful" />
    </view-state>

    <action-state id="validateAccount">
        <evaluate expression="employeeAction.GetEmployee(flowScope.username, oldPassword)"
            result="editBean" />
        <transition to="checkUserAccount" />
    </action-state>

    <action-state id="getId">
        <evaluate expression="employeeAction.GetEmployee(flowScope.username)"
            result="deleteBean" />
        <transition to="deleteUser" />
    </action-state>

    <decision-state id="checkUserAccount">
        <if test="editBean == null" then="queryAll"
            else="confirmPassword" />
    </decision-state>

    <decision-state id="confirmPassword">
        <if test="newPassword.equals(confirmPassword)" then="editUser1"
            else="queryAll" />
    </decision-state>

    <action-state id="editUser1">
        <set name="editBean.password" value="newPassword" />
        <transition to="editUser2" />
    </action-state>

    <action-state id="editUser2">
        <evaluate
            expression="employeeAction.editEmployee(editBean, authorityBean.authority)" />
        <transition to="editSuccessful" />
    </action-state>

    <action-state id="deleteUser">
        <evaluate expression="employeeAction.deleteEmployee(deleteBean)" />
        <transition to="editSuccessful" />
    </action-state>

    <end-state id="editSuccessful"
        view="externalRedirect:contextRelative:/admin_main.do" commit="true" />
    <end-state id="displayError" view="../xhtml/framework/displayError" />
    <end-state id="dummy1" view="../xhtml/framework/dummy" />

    <global-transitions>
        <transition on-exception="java.lang.Exception" to="displayError" />
    </global-transitions>

</flow>

我在这里的编辑功能遇到问题。在我的编辑页面中,我有用户名、旧密码、新密码和确认密码字段。

首先在 validateAccount 状态下,我检查数据库中是否存在用户名和旧密码,如果不存在,我会将其转发到 queryall 状态。

如果存在,我检查新密码和确认密码值是否相同,如果相同,我继续编辑。

如果没有,我再次返回到 queryAll。

QueryAll 状态获得用户在重新显示页面时将其填充到表单中的权限。当我将密码字段留空并且第一次单击编辑按钮时,它会抛出 java.lang.NullPointerException。

I have a Java web application using spring web flow.

How do I pass values from one flow to another flow?

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
    xmlns:c="http://java.sun.com/jsp/jstl/core" 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">

    <persistence-context />

    <var name="editBean" class="jp.co.anicom.domain.User" />
    <var name="deleteBean" class="jp.co.anicom.domain.User" />
    <var name="authorityBean" class="jp.co.anicom.domain.Authority" />


    <on-start>
        <set name="flowScope.username" value="requestParameters.username" />
    </on-start>

    <action-state id="queryAll">
        <evaluate expression="employeeAction.GetAuthority(flowScope.username)"
            result="authorityBean" />
        <transition to="editForm" />
    </action-state>

    <view-state id="editForm" model="editBean" view="../xhtml/framework/edit">
        <transition on="editButton" to="validateAccount" />
        <transition on="delete" to="getId" />
        <transition on="back" to="editSuccessful" />
    </view-state>

    <action-state id="validateAccount">
        <evaluate expression="employeeAction.GetEmployee(flowScope.username, oldPassword)"
            result="editBean" />
        <transition to="checkUserAccount" />
    </action-state>

    <action-state id="getId">
        <evaluate expression="employeeAction.GetEmployee(flowScope.username)"
            result="deleteBean" />
        <transition to="deleteUser" />
    </action-state>

    <decision-state id="checkUserAccount">
        <if test="editBean == null" then="queryAll"
            else="confirmPassword" />
    </decision-state>

    <decision-state id="confirmPassword">
        <if test="newPassword.equals(confirmPassword)" then="editUser1"
            else="queryAll" />
    </decision-state>

    <action-state id="editUser1">
        <set name="editBean.password" value="newPassword" />
        <transition to="editUser2" />
    </action-state>

    <action-state id="editUser2">
        <evaluate
            expression="employeeAction.editEmployee(editBean, authorityBean.authority)" />
        <transition to="editSuccessful" />
    </action-state>

    <action-state id="deleteUser">
        <evaluate expression="employeeAction.deleteEmployee(deleteBean)" />
        <transition to="editSuccessful" />
    </action-state>

    <end-state id="editSuccessful"
        view="externalRedirect:contextRelative:/admin_main.do" commit="true" />
    <end-state id="displayError" view="../xhtml/framework/displayError" />
    <end-state id="dummy1" view="../xhtml/framework/dummy" />

    <global-transitions>
        <transition on-exception="java.lang.Exception" to="displayError" />
    </global-transitions>

</flow>

I am having a problem with the edit functionality here. In my edit page I have username, oldpassword, newpassword and confirm password fields.

First in validateAccount state I check if the username and oldpassword exists in the database, if it it doesn't exist I forward it to queryall state.

If it exists I check if the new password and confirmpassword values are the same, if they are the same I proceed with the editing.

If not I return again to queryAll.

QueryAll state gets the authority of the user to populate it in the form upon re-displaying the page. When I leave the password fields blank and the first time I click edit button It throws a java.lang.NullPointerException.

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

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

发布评论

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

评论(1

雄赳赳气昂昂 2024-08-21 05:50:18

将两个流创建为子流,然后每个流中的数据应在父流和其他子流中可用。

将数据映射到子流发生
在子流会话开始之前。
将数据从子流映射回
父流程完成时
子流程完成,父流程完成
会话继续。

Create your two flows as subflows and then the data in each flow should be available in the parent and the other subflows.

Mapping data to the subflow happens
before the subflow session is started.
Mapping data from the subflow back to
the parent flow is done when the
subflow completes and the parent flow
session resumes.

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