aspose file tools*
The moose likes Struts and the fly likes s:if String comparison not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "s:if String comparison not working" Watch "s:if String comparison not working" New topic
Author

s:if String comparison not working

D kukreja
Ranch Hand

Joined: Jan 29, 2008
Posts: 39
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jan 29, 2008
Posts: 39
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

Joined: Sep 29, 2008
Posts: 12617

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: s:if String comparison not working