2013-10-11 49 views
1

我正在學習Spring和webflow,我遇到了一些看起來應該很簡單的問題。我的流程捕獲查詢字符串參數並在流程開始時將其存儲在流程範圍變量中。我試圖在第一個視圖狀態上回顯它。錯誤隨之而來。可以從JSP訪問flowScope條目嗎? (「Property ... not found on type org.springframework.webflow.core.collection.LocalAttributeMap」)

這裏的流程定義:

<?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"> 
    <on-start> 
     <set name="flowScope.foo" value="requestParameters.fubar" /> 
    </on-start> 
    <view-state id="step1" view="../jsp/step1.jsp"> 
     <transition on="next" to="step2" /> 
    </view-state> 
    <view-state id="step2" view="../jsp/step2.jsp"> 
     <transition on="next" to="step3" /> 
     <transition on="prev" to="step1" /> 
    </view-state> 
    <view-state id="step3" view="../jsp/step3.jsp"> 
     <transition on="prev" to="step2" /> 
     <transition on="next" to="done" /> 
    </view-state> 
    <end-state id="done" view="endView" /> 
    <end-state id="cancelled" view="../jsp/cancelledView.jsp" /> 
    <global-transitions> 
     <transition on="cancel" to="cancelled" /> 
    </global-transitions> 
</flow> 

step1.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Step 1</title> 
</head> 
<body> 
This is step 1 
     <h1>flowRequestContext.flowScope: ${flowRequestContext.flowScope}</h1> 
     <h1>flowRequestContext.flowScope["foo"]: ${flowRequestContext.flowScope["foo"]}</h1> 
     <h2>${flowScope}</h2> 
     <c:if test="${empty flowScope}"> 
      <h1>FLOW SCOPE IS EMPTY!</h1> 
     </c:if> 
     <c:if test="${!empty flowScope}"> 
      <h1>FLOW SCOPE IS *NOT* EMPTY!</h1> 
     </c:if> 
     <c:if test="${empty flowRequestContext.flowScope}"> 
      <h1>flowRequestContext.FLOW SCOPE IS EMPTY!</h1> 
     </c:if> 
     <c:if test="${!empty flowRequestContext.flowScope}"> 
      <h1>flowRequestContext.FLOW SCOPE IS *NOT* EMPTY!</h1> 
     </c:if> 
<form:form id="myForm"> 
    <input type="submit" id="next" name="_eventId_next" value="Next" /> 
    <input type="submit" name="_eventId_cancel" value="Cancel" /> 
</form:form> 
</body> 
</html> 

產生的錯誤:

javax.el.PropertyNotFoundException: Property 'foo' not found on type org.springframework.webflow.core.collection.LocalAttributeMap 
    javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:223) 
    javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:200) 
    javax.el.BeanELResolver.property(BeanELResolver.java:311) 
    javax.el.BeanELResolver.getValue(BeanELResolver.java:85) 
    javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67) 
    org.apache.el.parser.AstValue.getValue(AstValue.java:169) 
    org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189) 
    ... 

如果我省略了試圖訪問密鑰 「富」 了頁面呈現與以下輸出(其中查詢字符串是?fubar=baz):

This is step 1 
flowRequestContext.flowScope: map['foo' -> 'baz', 'viewScope' -> map[[empty]]] 
FLOW SCOPE IS EMPTY! 
flowRequestContext.FLOW SCOPE IS *NOT* EMPTY! 

它看起來像標識符flowRequestContext.flowScope確實提到過的地圖,它看起來像它包含我期望的鍵和值...但是,如果我嘗試訪問它就像一張地圖在EL沒有關係不合作。

回答

2

只是使用${foo}您的流量計中的所有物品都應該可以使用$