Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-2244

Allow overriding of the Validator default MessageKey

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.4-RC2
    • Fix Version/s: 1.5.2, 1.5.5
    • Component/s: wicket
    • Labels:
      None

      Description

      Currently there is no other way to change the default message key of any validator. Provide a protected non final method: getMessageKey() to allow overriding of the message key. For example for MinimumValidator:

      [CODE]
      public void validate(IValidatable<Z> validatable)
      {
      Z value = validatable.getValue();
      if (value.compareTo(minimum) < 0)

      { ValidationError error = new ValidationError(); error.addMessageKey(getMessageKey()); error.setVariable("minimum", minimum); validatable.error(error); }

      }

      protected String getMessageKey()

      { return "MinimumValidator"; }

      [CODE]

      There are no Sub-Tasks for this issue.

        Activity

        Hide
        mgrigorov Martin Grigorov added a comment -

        Fixed!
        Thanks, Bertrand!

        Funny, I reported similar bug to another project few days ago...

        Show
        mgrigorov Martin Grigorov added a comment - Fixed! Thanks, Bertrand! Funny, I reported similar bug to another project few days ago...
        Hide
        berniegp Bertrand Guay-Paquet added a comment -

        This commit broke the validator messages for classes extending MaximimumValidator, MinimumValidator, and RangeValidator.

        To reproduce, go to wicket-examples/dates and submit an invalid "hours" value (e.g. -2) in the "Example using DateTimeField".

        Prior to this, the resource key was set to a hard coded value. Now it is Classes.simpleName(getClass()). DateTimeField uses a custom RangeValidator subclass (HoursValidator) so it can't find the resource key anymore.

        I think it would be prudent to use the previously hard coded key values in the new resourceKey() method so subclasses not wanting to override the default message key can still use it.

        Show
        berniegp Bertrand Guay-Paquet added a comment - This commit broke the validator messages for classes extending MaximimumValidator, MinimumValidator, and RangeValidator. To reproduce, go to wicket-examples/dates and submit an invalid "hours" value (e.g. -2) in the "Example using DateTimeField". Prior to this, the resource key was set to a hard coded value. Now it is Classes.simpleName(getClass()). DateTimeField uses a custom RangeValidator subclass (HoursValidator) so it can't find the resource key anymore. I think it would be prudent to use the previously hard coded key values in the new resourceKey() method so subclasses not wanting to override the default message key can still use it.
        Hide
        mgrigorov Martin Grigorov added a comment -

        Improved with r1180956.

        Show
        mgrigorov Martin Grigorov added a comment - Improved with r1180956.
        Hide
        mpieters Martin Pieters added a comment -

        Out of curiosity why do MaximimumValidator, MinimumValidator, and RangeValidator not extend from AbstractValidator, which already offers this functionality?

        Show
        mpieters Martin Pieters added a comment - Out of curiosity why do MaximimumValidator, MinimumValidator, and RangeValidator not extend from AbstractValidator, which already offers this functionality?

          People

          • Assignee:
            mgrigorov Martin Grigorov
            Reporter:
            alexandru.objelean Alexandru Objelean
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development