Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-3389

Nicer handling of Java 5 enums by the Spring MVC form taglib.

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.0 M2
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                sandrews Scott Andrews
                Reporter:
                wshields William Shields
                Last updater:
                Trevor Marshall
              • Votes:
                1 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  9 years, 19 weeks, 1 day ago