Can flowScope entries be accessed from JSPs? ("Property ... not found on type org.springframework.webflow.core.collection.LocalAttributeMap")

StackOverflow https://stackoverflow.com/questions/19324448

  •  30-06-2022
  •  | 
  •  

Question

I'm learning Spring and webflow and I'm having trouble with something which seems like it should be simple. My flow is capturing a query string parameter and stashing it in a flow-scoped variable when the flow begins. I'm trying to echo it on the first view-state. Errors ensue.

Here's the flow definition:

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

Resulting error:

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

If I omit the attempt to access the key "foo" the page renders with the following output (where the query string is ?fubar=baz):

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

It looks like the identifier flowRequestContext.flowScope does refer to a map, and it looks like it does contain the key and value I would expect... but if I try to access it like a map in EL it doesn't cooperate.

Was it helpful?

Solution

just use ${foo} everything in your flowscope should be accessible with $

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top