2009-12-09 65 views
1

我有一個使用spring web flow的Java web應用程序。Spring Web 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> 

我遇到了編輯功能的問題。在我的編輯頁面中,我有用戶名,舊密碼,新密碼和確認密碼字段。

首先在validateAccount狀態我檢查數據庫中是否存在用戶名和oldpassword,如果它不存在我將它轉發到queryall狀態。

如果存在,我檢查新密碼和confirmpassword值是否相同,如果它們相同,則繼續編輯。

如果不是,我再次返回到queryAll。

QueryAll狀態獲得用戶在重新顯示頁面時在窗體中填充它的權限。當我將密碼字段留空並且第一次單擊編輯按鈕時,它會拋出一個java.lang.NullPointerException異常。

回答

1

將您的兩個流創建爲子流,然後每個流中的數據應在父流和其他子流中可用。

在子流會話開始之前,將數據映射到子流發生 。 將數據從子流映射回 父流將在 子流完成並且父流 會話恢復時完成。

+0

在我的問題中添加了以上內容... – cedric 2009-12-09 16:29:17

相關問題