aspose file tools*
The moose likes Struts and the fly likes Struts 2 - conditional check of IteratorStatus inside an s:if tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 - conditional check of IteratorStatus inside an s:if tag" Watch "Struts 2 - conditional check of IteratorStatus inside an s:if tag" New topic
Author

Struts 2 - conditional check of IteratorStatus inside an s:if tag

Mark Brownengland
Greenhorn

Joined: Apr 30, 2006
Posts: 26
Hi,

I have the following code snippet for iterating over a list and outputting index values based upon verifying the index number equals 0:




Before creating the above, I had the following:



This correctly outputted the index number for all elements in the iterator.

For some reason, when I include an s:if tag (as per my first snippet) and attempt to test the rowStatus index i.e. rowStatus.index == 0, this fails to evaluate and thus is never evaluated as true. As an aside, if I altered the first code snippet to:



In this instance, the s:if tag evaluates the test and alternately prints out the index number.

Would appreciate advice as to why I can't use the rowstatus.index inside an s:if tag.

Thanks in advance.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'd try %{#rowStatus.index == 0} first.

Note that there's an isFirst() method, so %{rowStatus.first} should accomplish the same thing.
Mark Brownengland
Greenhorn

Joined: Apr 30, 2006
Posts: 26
That's worked. I would appreciate an explanation as to why an int evaluation requires a #:



whereas a boolean primitive evaluation doesn't:

Mark Brownengland
Greenhorn

Joined: Apr 30, 2006
Posts: 26
Now sorted. It seems the # is always required. If using the form: %{} what is the need for inserting a # symbol before the variable name?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It depends partially on the version of S2 you're using. At some point a change was made to "eliminate" the confusing "#" character--but in my experience, not all usages are eliminated. I'm not really sure why not, and haven't yet taken the time to figure it out.

When it's used it's used to signify what I call a "stack context" variable. The value stack isn't just a stack--it's also a map. When a variable is created in the JSP page it's a stack context variable--not on the stack (unless you do an <s:push>), but along side it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2 - conditional check of IteratorStatus inside an s:if tag
 
Similar Threads
selecting a row in s:iterator
Struts2 test condition in s:if not working
Problem using <s:if tag of Struts2
Struts 2 iterating enums