Access Enum value using EL with JSTL

IaCoder picture IaCoder · Sep 23, 2008 · Viewed 118.2k times · Source

I have an Enum called Status defined as such:

public enum Status { 

    VALID("valid"), OLD("old");

    private final String val;

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

    public String getStatus() {
        return val;
    }

}

I would like to access the value of VALID from a JSTL tag. Specifically the test attribute of the <c:when> tag. E.g.

<c:when test="${dp.status eq Status.VALID">

I'm not sure if this is possible.

Answer

Alexander Vasiljev picture Alexander Vasiljev · Dec 15, 2008

A simple comparison against string works:

<c:when test="${someModel.status == 'OLD'}">