This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes How to compare Enums using Struts if tag? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to compare Enums using Struts if tag?" Watch "How to compare Enums using Struts if tag?" New topic
Author

How to compare Enums using Struts if tag?

Piyush Paramane
Greenhorn

Joined: Jul 17, 2012
Posts: 5
Hi,

I have an Enum in my bean, public enum Gender {male,female,unknown};
I am getting already selected enum value from previous JSP, now i want to compare it in my JSP and write some logic using struts tags.

e.g.
<s:if test="%{session.myBean.myGender == session.myBean.Gender.male}>
//Write some login when selected enum is male </s:if>
<s:if test="%{session.myBean.myGender == session.myBean.Gender.female}>
//Write some login when selected enum is female </s:if>
<s:else></s:else>

is it the correct way? i am not able to get selected enum value and it always enters in else part.
What would be the solution for this?
 
wood burning stoves
 
subject: How to compare Enums using Struts if tag?
 
Similar Threads
s:if Question
s:if String comparison not working
IF condition in Struts 2.1.6
Jsp struts tag to check null values
struts 2 s:if tag