Wicket
  1. Wicket
  2. WICKET-3879

Support FormValidator and package level resource bundles

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.0.0-beta1
    • Component/s: wicket
    • Labels:
      None

      Description

      Basically allow the following to work:

      public class MyValidator extends AbstractValidator {
      protected void onValidate(IValidatable v)

      { error(v); }

      }

      MyValidator.properties
      MyValidator=$

      {label} is invalid

      MyValidator_nl.properties
      MyValidator=${label}

      is niet goed

      Igor also asked for package level resource bundles

        Issue Links

          Activity

          Hide
          Sylvain Vieujot added a comment -

          It seems WICKET-1103 solve the issue for a Validator attached to a field, but it does not work for an AbstractFormValidator.
          A FormValidator usually reports an error to one of the Form's field.

          Example :
          public class NewUserValidator extends AbstractFormValidator {

          private final EmailTextField loginField;

          public NewUserValidator(EmailTextField loginField)

          { this.loginField = loginField; if( loginField == null ) throw new IllegalArgumentException( "argument loginField cannot be null" ); }

          @Override
          public FormComponent<?>[] getDependentFormComponents() {
          return new FormComponent[]

          { loginField }

          ;
          }

          @Override
          public void validate(@SuppressWarnings( "unused" ) Form<?> form) {
          final String login = loginField.getValue();

          if( StringUtils.isNotBlank( login ))

          { WebUser sameLogin = new WebUserDAO().getByLogin( login ); if( sameLogin != null ) error( loginField ); }

          }
          }

          Reports an error message :
          Could not locate error message for component: EmailTextField@joiningForm:login and error: [ValidationError message=[null], keys=[NewUserValidator], variables=[[label0=login],[name0=login],[input0=wer@toto.com]]]. Tried keys: login.NewUserValidator, NewUserValidator.

          The reason seems to be that an AbstractFormValidator is not attached to a Field, and ValidatorStringResourceLoader looks in the form component's behaviours.
          But as the validator is a form validator, it is not in the component's behaviours :
          See ValidatorStringResourceLoader, line 81 to 90.

          Show
          Sylvain Vieujot added a comment - It seems WICKET-1103 solve the issue for a Validator attached to a field, but it does not work for an AbstractFormValidator. A FormValidator usually reports an error to one of the Form's field. Example : public class NewUserValidator extends AbstractFormValidator { private final EmailTextField loginField; public NewUserValidator(EmailTextField loginField) { this.loginField = loginField; if( loginField == null ) throw new IllegalArgumentException( "argument loginField cannot be null" ); } @Override public FormComponent<?>[] getDependentFormComponents() { return new FormComponent[] { loginField } ; } @Override public void validate(@SuppressWarnings( "unused" ) Form<?> form) { final String login = loginField.getValue(); if( StringUtils.isNotBlank( login )) { WebUser sameLogin = new WebUserDAO().getByLogin( login ); if( sameLogin != null ) error( loginField ); } } } Reports an error message : Could not locate error message for component: EmailTextField@joiningForm:login and error: [ValidationError message= [null] , keys= [NewUserValidator] , variables=[ [label0=login] , [name0=login] , [input0=wer@toto.com] ]]. Tried keys: login.NewUserValidator, NewUserValidator. The reason seems to be that an AbstractFormValidator is not attached to a Field, and ValidatorStringResourceLoader looks in the form component's behaviours. But as the validator is a form validator, it is not in the component's behaviours : See ValidatorStringResourceLoader, line 81 to 90.
          Hide
          Martin Grigorov added a comment -

          In Wicket 6.0 IFormValidator can also have its own resource bundle as other IValidator's.

          There is a comment in IFormValidator to make it implement IValidator and this will lead to a simplification in ValidatorStringResourceLoader but this will lead also to some API breaks which we try to avoid unless really needed.

          Show
          Martin Grigorov added a comment - In Wicket 6.0 IFormValidator can also have its own resource bundle as other IValidator's. There is a comment in IFormValidator to make it implement IValidator and this will lead to a simplification in ValidatorStringResourceLoader but this will lead also to some API breaks which we try to avoid unless really needed.

            People

            • Assignee:
              Martin Grigorov
              Reporter:
              Sylvain Vieujot
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development