Wicket
  1. Wicket
  2. WICKET-4864

'format' not set in ConversionException

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 6.2.0
    • Fix Version/s: 6.3.0
    • Component/s: wicket-datetime
    • Labels:
      None

      Description

      There are two DateConverter implementations in wicket:
      [1] wicket.util.convert.DateConverter
      [2] wicket.datetime.DateConverter

      When an error occures while converting the input, both throw a ConversionException. This ConversionException has a property called 'format' which is later used to get a localized pattern for error messages. But since they base on different formatter classes (jdk/joda-time), the formatter of [2] is incompatible to the format property.

      So I can see 2 ways of solving this issue:
      1. put an already localized pattern as a variable (also named 'format') in ConversionException (using ConversionException .setVariable() - those variables are later also applied to the error message)
      2. Alter the class ConversionException so its property 'format' holds the localized pattern as a string, instead of an instance of SimpleDateFormat

      1. DateConverter.patch
        1 kB
        Benedikt Schlegel

        Activity

        Hide
        Martin Grigorov added a comment -

        Solution #2 wont work. DateFormat has no localized pattern, only SimpleDateFormat has it.

        Can you attach a patch for solution #1 ?

        Show
        Martin Grigorov added a comment - Solution #2 wont work. DateFormat has no localized pattern, only SimpleDateFormat has it. Can you attach a patch for solution #1 ?
        Hide
        Benedikt Schlegel added a comment -

        Here you go, patch for solution #1
        -
        Yet I don't understand why #2 should not work. Obviously it's possible to get a localized pattern of that ConversionException thrown by o.a.w.util.DateConverter, see FormComponent.reportValidationError():

        Format format = e.getFormat();
        if (format instanceof SimpleDateFormat)

        { error.setVariable("format", ((SimpleDateFormat)format).toLocalizedPattern()); }

        So it should also be possible to extract a pattern before creating the exception instance. Also, this is the only usage of ConversionException.getFormat(), so I think it would be just fine to change the type of the field 'format' and it's getter/setter.

        Show
        Benedikt Schlegel added a comment - Here you go, patch for solution #1 - Yet I don't understand why #2 should not work. Obviously it's possible to get a localized pattern of that ConversionException thrown by o.a.w.util.DateConverter, see FormComponent.reportValidationError(): Format format = e.getFormat(); if (format instanceof SimpleDateFormat) { error.setVariable("format", ((SimpleDateFormat)format).toLocalizedPattern()); } So it should also be possible to extract a pattern before creating the exception instance. Also, this is the only usage of ConversionException.getFormat(), so I think it would be just fine to change the type of the field 'format' and it's getter/setter.

          People

          • Assignee:
            Martin Grigorov
            Reporter:
            Benedikt Schlegel
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development