Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.4
    • Fix Version/s: 2.0.5
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      BeanWrapperImpl uses TypeConverterDelegate. This class is not open to extension and not easily pluggable in a Spring MVC or Webflow environment. That aside, it has what I consider to be a bug. In convertIfNecessary() you have the following fallback code block for Java 5 enums:

      try

      { Field enumField = requiredType.getField((String) convertedValue); convertedValue = enumField.get(null); }

      catch (Throwable ex) {
      if (logger.isTraceEnabled())

      { logger.trace("Field [" + convertedValue + "] isn't an enum value", ex); }
      }

      IMHO this should be changed to:

      try {
      if (StringUtils.hasText((String)convertedValue) { Field enumField = requiredType.getField((String) convertedValue); convertedValue = enumField.get(null); } else { convertedValue = null; }
      }
      catch (Throwable ex) {
      if (logger.isTraceEnabled()) { logger.trace("Field [" + convertedValue + "] isn't an enum value", ex); }

      }

      This is to circumvent a problem where you can't set null values for Java 5 enum properties, which is particularly a problem for Web pages. Consider the example:

      <form:select path="gender">
      <form:option value="" label="Select One"/>
      <form:option value="MALE" label="Male"/>
      <form:option value="FEMALE" label="Female"/>
      </form:select>

      assuming:

      public enum Gender

      { MALE, FEMALE; }

      and the gender property being of type Gender.

      This forces you to:

      • use a custom property editor;
      • use an empty dummy value (like a Gender instance of NOT_SELECTED); or
      • not use Java 5 enums.

      Not selecting an option (translating to a null value) is a valid and common scenario. A custom property editor shouldn't be required for this.

        Attachments

          Activity

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              wshields William Shields
              Last updater:
              Spring Issuemaster
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                39 weeks, 5 days ago