JSP: Enumeration Access Inside JSP EL Tags

My java enum is as follows:

public enum EmailType { HOME, WORK, MOBILE, CUSTOMER_SERVICE, OTHER } 

In JSP, I am trying to do something like below that does not work.

 <c:choose> <c:when test="${email.type == EmailType.HOME}">(Home)</c:when> <c:when test="${email.type == EmailType.WORK}">(Work)</c:when> </c:choose> 

After googling, I found these links: Enumeration inside JSP . But I want to avoid using scripts in my JSP. How can I access a java enumeration inside an EL tag and do a comparison? Please, help.

+8
jsp
source share
1 answer

When an enumeration is serialized, it becomes a string. So just use string comparison.

 <c:choose> <c:when test="${email.type == 'HOME'}">(Home)</c:when> <c:when test="${email.type == 'WORK'}">(Work)</c:when> </c:choose> 
+7
source share

All Articles