This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Struts and the fly likes s:if Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "s:if Question" Watch "s:if Question" New topic
Author

s:if Question

David Ogasawara
Greenhorn

Joined: Oct 11, 2001
Posts: 13
I'm new to Struts 2 and I'm trying to figure out why my s:if is not working.

If I enter this:

it returns Y.

However, if I enter this:

It returns No.


What am I doing wrong?
[ May 23, 2008: Message edited by: David Martin ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The expressions you are using are OGNL expresssions, not Java expressions. The expression "#{session.admin}" is a valid OGNL expression, while "#{session.admin.trim()}" is not.


Merrill
Consultant, Sima Solutions
David Ogasawara
Greenhorn

Joined: Oct 11, 2001
Posts: 13
Thank you for your assistance. However, I changed the code and it still gives me the incorrect response.



Could the problem be that I'm comparing a String to a char? If so, how is this solved?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The condition goes inside the brackets. try
David Ogasawara
Greenhorn

Joined: Oct 11, 2001
Posts: 13
Thank you for your help! I figured out the problem. I initially set the session variable as a String (session.setAttribute("admin", "Y")). Changing it to a char (session.setAttribute("admin", 'Y')) solved the problem.
 
 
subject: s:if Question