You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Spring MVC form tag library is different and uses toString(). A similar issue was raised in Spring Webflow and fixed in the latest 1.0.2 release. This should also be fixed in Spring MVC. The default implementation of a Java 5 enum is effectively:
public String toString() { return name(); }
however it is reasonable and common to override this. For example:
public String toString() {
return description;
}
}
Why do this? Because the name can be considered the value whereas the toString() can be viewed as the description the user sees and selects, which brings up the issue that there really isn't a nice way to do this.
Affects: 2.0.4
The text was updated successfully, but these errors were encountered:
William Shields opened SPR-3388 and commented
In XML Spring config files, you can use name() of an enum value when setting the property, for example:
<bean id="person1">
<property name="gender" value="MALE"/>
...
</bean>
for
public enum Gender { MALE, FEMALE };
It does this lookup based on name().
The Spring MVC form tag library is different and uses toString(). A similar issue was raised in Spring Webflow and fixed in the latest 1.0.2 release. This should also be fixed in Spring MVC. The default implementation of a Java 5 enum is effectively:
public String toString() { return name(); }
however it is reasonable and common to override this. For example:
public Gender {
MALE("Male"),
FEMALE("Female");
private String description;
Gender(String description) {
this.description = description;
}
public String toString() {
return description;
}
}
Why do this? Because the name can be considered the value whereas the toString() can be viewed as the description the user sees and selects, which brings up the issue that there really isn't a nice way to do this.
Affects: 2.0.4
The text was updated successfully, but these errors were encountered: