• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

compare iterator variable with variable outside iterator  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm having problems usinf a variable from outside an iterator. In my action bean, I have a variable called resultTypeID. I also have a collection of objects called results. Each results object contains a value called resultTypeID.

In the jsp file I have the following code:

<s:iterator value="results" id="res" status="rowstatus">
<a href="page?resultTypeID=<s:property value="resultTypeID">&...>
</s:iterator>

The property passed in the anchor is the resultTypeID value from the results object. I want it to pass the resultTypeID from the action bean. Is there a way to do this? Please help. Thanks!
 
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several options, including but not limited to:

  • You can use OGNL's stack array notation ([1].resultTypeId or something like that) to directly reference a stack object not on the top.
  • You could <s:set...> a new variable with the action property before the <s:iterator...> tag, which is arguably a little cleaner and robust.
  • You could provide a getter in the action with a unique name that just returns getResultTypeID().

  • Those are the ones I think of off the top of my head.
     
    Casey Marshall
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks! I tried option 2 and it worked fine.
     
    Don't get me started about those stupid light bulbs.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!