可以从JSP访问flowScope条目吗? (“属性...未在类型org.springframework.webflow.core.collection.LocalAttributeMap上找到”)

时间:2013-10-11 17:57:42

标签: el spring-webflow

我正在学习Spring和webflow,而我遇到的问题似乎应该很简单。我的流程正在捕获查询字符串参数,并在流程开始时将其存储在流范围的变量中。我试图在第一个视图状态上回应它。错误随之而来。

这是流程定义:

<?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)
    ...

如果我省略了访问密钥“foo”的尝试,则页面将使用以下输出呈现(查询字符串为?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中的地图那样访问它那么它就不会合作。

1 个答案:

答案 0 :(得分:3)

只需使用${foo}您可以使用$

访问流量计中的所有内容