3

I have an enum

public enum Number
 {
 ONE("one"), TWO("two"), THREE("three"), FOUR("four");
 }

i put this enum into model

model.addAttribute("myEnum", Number.values());

Now, in jsp page I want to show a value of one of these enums.

<c:out value="${myEnum.ONE}"/>

but it doesnt seem to work. What am I doindg wrong?

1 Answer 1

4

myEnum is a list of values returned, you could either create one attribute equal to the value of one enum instance :

model.addAttribute("one", Number.ONE);

<c:out value="${one}"/>

or loop through myEnum :

<c:forEach items="${myEnum}" var="value">
    ${value}
</c:forEach>
Sign up to request clarification or add additional context in comments.

1 Comment

Is there a solution where we can pass the actual enum instead of casting to an array, then iterating over the array until finding the value we want?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.