Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compare iterator variable with variable outside iterator

 
Casey Marshall
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!
 
David Newton
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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic