Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mark Brownengland
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic