jyriand
jyriand

Reputation: 2524

showing value of enum in jsp using spring mvc

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?

Upvotes: 3

Views: 5642

Answers (1)

NimChimpsky
NimChimpsky

Reputation: 47280

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>

Upvotes: 4

Related Questions