wood burning stoves
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

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
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

How do I access a page scoped object.

David Dunham

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

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

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

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.

David Dunham

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

In order to access a page context variable:

<select ...
I agree. Here's the link: http://aspose.com/file-tools
subject: How do I access a page scoped object.
jQuery in Action, 3rd edition