1

我正在学习 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 中的映射一样访问它,它就不会合作。

4

1 回答 1

3

只需使用${foo}您的 flowscope 中的所有内容,应该可以通过 $ 访问

于 2013-10-11T18:14:58.200 回答