I am facing an issue populating a dropdown list from Enum class values. My enum class code is:
package abc.xyz.constants;
public enum StateConstantsEnum
{
NEWYORK("NY"),
FLORIDA("FL"),
CALIFORNIA("CA"),
private String fullState;
private StateConstantsEnum( String s )
{
fullState = s;
}
public String getState()
{
return fullState;
}
}
I want populate dropdown list with NEWYORK, FLORIDA and CALIFORNIA. I am creating and adding the list to Spring model this way:
List<StateConstantsEnum> stateList = new ArrayList<StateConstantsEnum>( Arrays.asList(StateConstantsEnum.values() ));
model.addAttribute("stateList", stateList);
Then I am trying to populate the dropdown in JSP using:
<select name="${status.expression}" name="stateLst" id="stateLst">
<option value=""></option>
<c:forEach items="${stateList}" var="option">
<option value="${option}">
<c:out value="${option.fullState}"></c:out>
</option>
</c:forEach>
</select>
But I am getting an exception "Exception created : javax.el.PropertyNotFoundException: The class 'abc.xyz.constants.StateConstantsEnum' does not have the property 'fullState'."
How do I fix this problem? Help much appreciated
<c:out value="${option.state}"></c:out>
would be correct. – Magdala