File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to compare Enums using Struts if tag?
 
Similar Threads
struts 2 s:if tag
IF condition in Struts 2.1.6
Jsp struts tag to check null values
s:if String comparison not working
s:if Question