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-projects-issues opened this issue Apr 18, 2007 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

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-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

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

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 2.0.5 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants