aspose file tools*
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 Spring in Action this week in the Spring 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.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
     
    subject: compare iterator variable with variable outside iterator