File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How do I access a page scoped object. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How do I access a page scoped object." Watch "How do I access a page scoped object." New topic
Author

How do I access a page scoped object.

David Dunham
Greenhorn

Joined: Jan 23, 2009
Posts: 9
I have the following code in my jsp:
<mytaglib:getRunners var="runners" />
Runners: "${runners}"<br/>${runners[0].name}<br/>${runners[0].description}<br/>
<s:select ...
list="runners"
listKey="name"
listValue="description"
.../>

--
Runners is an list of objects with getName() and getDescription() functions.
When I comment out the select, I can see that the runners variable is being set by the taglib.
But no matter what I've tried I can't get the select to find the object.
I've tried the following: ${runners}, runners, %{runners}, and a couple of other variations. Is there no way to get the list of objects from the page scope? I'm pretty sure I'm missing something simple here, but I've been googling and searching for a solution for several hours, and I can't find the way to solve this.

Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
I don't know what is the <s:select> however may be you can't get it because you can't use EL expressions with that tag so try to check its tld to remove that doubt. in general you could be able to access the runners object in EL as follows:

${runners} assuming runners is a bean or a map
or ${pageContext.runners}
or ${pageContext['runners']}


Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
David Dunham
Greenhorn

Joined: Jan 23, 2009
Posts: 9
I should have been more clear, sorry.
This is struts 2, I've tried the el notation and it gives me a stack dump in the logfile, the tld doesn't allow that.

I can do: list="#{'runner1':'desc 1','runner2':'desc 2'}"
and that works (no need of the listKey and listValue), but I want to populate this dynamically from the database.

According to the documentation the 'list' attribute is supposed to be a collection/list, I've got my list of runners in the page context via my tag lib but I don't know the OGNL notation or way to get the object 'runner' from the page context.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

#attr will search all the JEE scopes.

The two main OGNL pages on the S2 documentation wiki show more.

http://struts.apache.org/2.x/docs/ognl.html
http://struts.apache.org/2.x/docs/ognl-basics.html
David Dunham
Greenhorn

Joined: Jan 23, 2009
Posts: 9
That worked, thanks.

In order to access a page context variable:

<select ...
list="#attr.runners"
...
/>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I access a page scoped object.
 
Similar Threads
Servlet Doesn't appear to be working.
Using EL to loop through a List and display all its properties
Options Tag not Recognizing Collection
Searching for a better way of stripping a file
Struts 2 Aggregated Lists and Select Boxes