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

s:if String comparison not working

 
D kukreja
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a map in my action , and iterating thru it in my jsp.
the s:if comparison works in some cases and doesn't work sometimes.the s roperty prints "Yes" , but still the else block is executed.

heres the code
<s:iterator value="isTrailAvailable">
<s:if test='key.equals("${templang1}")'>
<s roperty value="value"/> //prints Yes here
<s:if test='value.trim().equals("Yes")'>
YES:::<s roperty value="value"/>
</s:if>
<s:else>
NO:::<s roperty value="value"/> //prints Yes here</s:else>
</s:if>
</s:iterator>
not sure why it wud go to else block when the value printed is Yes.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use the UBB "code" tags when posting code, and disable smilies.



The first thing I would consider is that I doubt there's any practical way to determine *which* <s:if...> the <s:else...> is associated with, which could lead to unexpected results.

Is the value of "value" actually "Yes", with no spaces? (If so, why bother with the trim before the compare?)
 
D kukreja
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know the <s:else> is associated with second <s:if> since it is printing the "NO::" and then value , which is "Yes". Also I tried to put trim , as it is not going to the if block sometimes. So, I thought it might have spaces.The value is actually "Yes" as it is printed on the screen as well..any more ideas?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you're looking at the rendered HTML and have print guard characters around the "yes" you won't know that it's actually "Yes" (no spaces).

Without seeing the data used to produce the error I can't run anything on my own; if you have the relevant action code available please post it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic