• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

s:if String comparison not working

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic