• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

compare iterator variable with variable outside iterator

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks! I tried option 2 and it worked fine.
     
    I'm doing laundry! Look how clean this tiny ad is:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic