This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes compare iterator variable with variable outside iterator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "compare iterator variable with variable outside iterator" Watch "compare iterator variable with variable outside iterator" New topic
Author

compare iterator variable with variable outside iterator

Casey Marshall
Greenhorn

Joined: Jan 28, 2009
Posts: 2
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

Joined: Sep 29, 2008
Posts: 12617

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

    Joined: Jan 28, 2009
    Posts: 2
    Thanks! I tried option 2 and it worked fine.
     
    Don't get me started about those stupid light bulbs.
     
    subject: compare iterator variable with variable outside iterator
     
    Similar Threads
    Iterating over HaspMap<String,List<Object>> and comparing values.
    Loop in JSP with Struts
    Struts 2: Using 2 actions in one JSP
    Struts2 - <s:iterator> in two-Dimensional Array.
    Issue in using <s:iterator /> within another <s:iterator />