This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2 test condition in s:if not working

 
Teresa Lee
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see my code below for my problem:

Note: pendingList is an action attribute and it contains a list of object A.

A.java

B.jsp


Output on jsp: NormalThereTest123

It looks to me that [0].type inside the test condition is treated as an object instead of a String. But I need to compare the value of type inside the loop. Anybody please help to solve my problem. Thanks.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the value equals "Normal" then the value also is not null.

Looks like it's working as it should be, but your code is incorrect.
 
Teresa Lee
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply, David.
The value does equal "Normal". However, "[0].type != null" returns true but "[0].type == 'Normal'" returns false and thus the "HereTest123" never got printed out. So I only thought that probrably [0].type is an object type and can't compare to a string.

I also tried this:


But never got into "do something here..." statement. Any ideas? Thanks again.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh; I got the "here" and "there" backwards.

I don't know what to tell you--either the data isn't as you expected, or something else in on the stack. There's no reason to use the [0] notation inside an iterator; either access the property directly, or put each object of iteration into a var and access it through that. The notation and tag works fine; it's used all the time.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic