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
fullState
is private, getState()
is the accessor.
<c:out value="${option.state}"></c:out>
Or rename your getter to getFullstate()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With