changeme
changeme

Reputation: 640

Enum description in JSP

I have a Enum with Key and description like below. In JSP I will be getting the value and I want to display the description.

public enum STATUS {
    ACTIVE("A", "Active"),
    INACTIVE("I","Inactive"),
    PENDING("PND","Pending");

private final String value;
    private final String description;

    public String getValue() {
        return value;
    }
    public String getDescription() {
        return description;
    }
    STATUS(String value, String description) {
        this.value=value;
        this.description = description;
    }

    public static STATUS fromValue(String value) {
        if (value != null) {
            for (STATUS status : values()) {
                if (status.value.equals(value)) {
                    return status;
                }
            }
        }
        return getDefault();
    }
}

Upvotes: 0

Views: 1193

Answers (1)

BalusC
BalusC

Reputation: 1108642

As you've there a valid Javabean-compliant getter method, you can just access it the usual Javabean way.

${status.description}

Or if it's referenced as a property of another javabean, then do so

${order.status.description}

Upvotes: 2

Related Questions