You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mark Ayad <ma...@javamark.com> on 2002/11/12 17:29:54 UTC
Re: Map iterate problem Application Scope
Map iterate problemThe iterate examples seem to use Maps that are created in the PageScope. In the case of a Map-backed action form.
However what I'm trying to do is iterate over a an Object placed in the application scope: a.k.a. I can't seem to get the <logic:iterate> to work even though the bean mm is sitting quite hapily in the application scope.
servlet.getServletContext().setAttribute("mm", new MultiMap());
public class MultiMap
{
public Map values = new HashMap();
public void setValue(String key, Object value) {
values.put(key, value);
}
public Object getValue(String key) {
return values.get(key);
}
public MultiMap()
{
values.put("foo","bar");
}
public Map getMap()
{
return values ;
}
}
Is the possible ?
Re: Map iterate problem Application Scope
Posted by Robert <rm...@bull-enterprises.com>.
I actually had this problem with other objects (not necessarily maps)
and it turned out that the logic and bean tags would only find my
objects if I set them in the pageContext object, meaning I would have to
do this in my JSP:
....
<% pageContext.setAttribute( "mm"
pageContext.getServletContext().getAttribute("mm"),
pageContext.APPLICATION ); %>
...
It sucked, but it worked. Essentially the tags were always looking in
the pageContext object and not the servletContext. Or maybe it was a
problem with the pageContext implementation in Tomcat, don't know which.
For JavaBeans, I could use a <jsp:useBean> tag that pointed to my bean
and the tags would find it as well. So if I set a bean in session /
request scope, say in an Action, I would have to use a jsp:useBean tag
on the page that defined the bean that was already there.
Robert
Mark Ayad wrote:
>Map iterate problemThe iterate examples seem to use Maps that are created in the PageScope. In the case of a Map-backed action form.
>
>However what I'm trying to do is iterate over a an Object placed in the application scope: a.k.a. I can't seem to get the <logic:iterate> to work even though the bean mm is sitting quite hapily in the application scope.
>
>servlet.getServletContext().setAttribute("mm", new MultiMap());
>
>public class MultiMap
>{
> public Map values = new HashMap();
>
> public void setValue(String key, Object value) {
> values.put(key, value);
> }
>
> public Object getValue(String key) {
> return values.get(key);
> }
>
> public MultiMap()
> {
> values.put("foo","bar");
> }
>
> public Map getMap()
> {
> return values ;
> }
>}
>
>Is the possible ?
>
>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>