Skip to content

Nicer handling of Java 5 enums by the Spring MVC form taglib. [SPR-3389] #8072

Closed
@spring-projects-issues

Description

@spring-projects-issues

William Shields opened SPR-3389 and commented

Enums aren't really handled well and could be handled much more nicely by some of the form tags. For example, form:select should be able to autopopulate enum values and would save a lot of boilerplate if this were the case. I'm thinking of a syntax like:

<form:select path="gender">
<form:option value="" label="Select One"/>
form:options/
</form:select>

The empty form:options in this case could, via a PropertyDescriptor, discover the type of the property (being enum Gender) and create the options based on Gender.values() with value of name() and label of toString(). Optional attributes could set the value and label properties eg:

<form:select path="gender" valueProperty="code">
<form:option value="" label="Select One"/>
<form:options labelProperty="description"/>
</form:select>

assuming:

public enum Gender {
MALE("M","Male"),
FEMALE("F","Female");

private String code;
private String description;

Gender(String code, String description) {
this.code = code;
this.description = description;
}

public String getCode() { return code; }
public String getDescription() { return description; }
public String toString() { return description; }
}

Additionally, I would suggest adding a new tag:

form:radioButtons/

to create groups of radio buttons.


Issue Links:

  • ROO-254 enums cannot be entered in web interface

Referenced from: commits 8e261e5

1 votes, 6 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions