My java enum looks like this:
public enum EmailType { HOME, WORK, MOBILE, CUSTOMER_SERVICE, OTHER }
In JSP, I am trying to do sth like below, which is not working.
<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: Enum inside a JSP. But, I want to avoid using scriplets in my JSP. How can I access the java enum inside EL tag and do the comparision?? Please help.
When an enum is serialized it becomes a string. So just use a string compare.
<c:choose>
<c:when test="${email.type == 'HOME'}">(Home)</c:when>
<c:when test="${email.type == 'WORK'}">(Work)</c:when>
</c:choose>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With