This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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?
 
jQuery in Action, 2nd edition
 
subject: How to compare Enums using Struts if tag?
 
Similar Threads
s:if String comparison not working
IF condition in Struts 2.1.6
s:if Question
Jsp struts tag to check null values
struts 2 s:if tag