• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Struts2 test condition in s:if not working

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
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
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
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
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic