I am using Spring framework and i want to add an object to the view using the addObject method of ModelAndView class. The object i want to pass is an array of all the available values of an enumeration. The method that i use to fetch all the available values of my enumeration is the static values() method. The problem is that when i am trying to fetch the values from jsp i am getting nothing.
The enumeration,
public enum MyEnumeration {
VALUE_A(1), VALUE_B(2);
private final int value;
private MyEnumeration(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
Source from the method on a controller.
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("myView");
modelAndView.addObject("myEnumerationList", MyEnumeration.values());
Source from the jsp file,
<h1>Size: ${myEnumerationList.length}</h1>
<h1>Size: ${myEnumerationList.size()}</h1>
<c:forEach items="${myEnumerationList}" var="category">
<div>${category}</div>
</c:forEach>
<c:forEach items="${myEnumerationList}" var="category">
<div>${category.getValue()}</div>
</c:forEach>
<c:forEach items="${myEnumerationList}" var="category">
<div>${category.toString()}</div>
</c:forEach>
The result on the browser is the above,
Size:
Size:
Aucun commentaire:
Enregistrer un commentaire