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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 test condition in s:if not working" Watch "Struts2 test condition in s:if not working" New topic
Author

Struts2 test condition in s:if not working

Teresa Lee
Greenhorn

Joined: Feb 01, 2008
Posts: 24
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Feb 01, 2008
Posts: 24
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

Joined: Sep 29, 2008
Posts: 12617

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