Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<form:*> tag library assumes the value of a Java 5 enum property is the value of toString() [SPR-3388] #8071

Closed
spring-issuemaster opened this issue Apr 18, 2007 · 1 comment

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Apr 18, 2007

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

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 25, 2007

Juergen Hoeller commented

Thanks for the report! This is fixed in CVS HEAD now.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.