0

I have a map, kinda like this defined in my spring context file.

<util:map id="myMap">
  <entry key="key1" value="myValue"/>
</util:map>

I would like to access this from my JSP inside of a webflow like this

<c:forEach var="item" items="${myMap}">
 <div>
  <c:out value="${item.key}"/>
 <div>
</c:forEach>

How do I do that? I am defining the map in the spring context, but its not being picked up in the webflow.

it works just fine if I have it in a regular java view controller, but the Webflow has an XML file that handles the view states, and I'm not sure how to pass variables into the view states beyond that.

2 Answers2

0

This approach has nothing to do with WebFlow, but if the map is intended to be a global singleton, you can get Spring beans onto "Application Scope" (a.k.a. ServletContext) using org.springframework.web.context.support.ServletContextAttributeExporter.

If you do this, any JSP can access it via EL like you've posted.

<bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
    <property name="attributes">
        <map>
            <entry key="myMap" value-ref="myMap"/>
        </map>
    </property>
</bean>
dbreaux
  • 4,982
  • 1
  • 25
  • 64
0

In the view state you wish to access this map, you can set a scoped variable to be accessible in the page. Request scope probably makes the most sense here; it will only be in scope for the duration of this particular view request. The value you'd set this to would be the bean id of that map you want to iterate over. (Alternatively, it could be the output of a method on a bean as well.)

<view-state id="someState" view="viewName">
    <on-render>
        <set name="requestScope.myMap" value="myMap"/>
    </on-render>
</view-state>

I'd recommend checking out the spring web flow documentation for more examples of the various scopes (flash, flow, etc) and the different events (on-render, on-entry, etc.)

kevin
  • 639
  • 1
  • 7
  • 9