• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I access a page scoped object.

 
David Dunham
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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']}
 
David Dunham
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That worked, thanks.

In order to access a page context variable:

<select ...
list="#attr.runners"
...
/>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic