2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

Access Enum value using EL with JSTL

I have this piece of code which I want to access from JSP using JSTL EL

public enum Status {

    APPLE("apple"), MANGO("mango");

    private final String val;

    Status(String val) {
        this.val = val;
    }

    public String getStatus() {
        return val;
    }

}


userimage

Yes you can simply able to write the below snippets:

1.Decaling the enum by scriptlet

<% pageContext.setAttribute("appke", Status.APPLE); %>

and compare like,

<c:when test="${someModel.status == apple}"/>...</c:when>

2.Using the constants directly.

<c:when test="${someModel.status eq 'APPLE'}">
Answer is