0 Replies Latest reply: Oct 26, 2012 2:31 AM by Sposh RSS

    Retrieving JSR 303 validation/constraints on UIInput

    Sposh
      Reposting a thread I originally posted on
      http://www.coderanch.com/t/596023/JSF/java/Retrieving-JSR-validation-constraints-UIInput
      in case anybody here had any more thoughts on the matter

      First a bit of background...

      I want to implement a bit of simple client-side validation using JavaScript/jQuery. The way it works is looking for certain classNames on the form inputs such as min3, required...

      Then I wanted to make this transparent to the programmer, so I extended the renderkit so for each component it looks at it's validators and injects these classNames:
      @Override
      public void writeAttribute(String name, Object value, String property) throws IOException {
      Object newValue = value;
      if (BKRenderKit.CLASS_NAME.equals(name)) {
      UIComponent component = UIComponent.getCurrentComponent(FacesContext.getCurrentInstance());
      if (component instanceof UIInput) {
      for (final Validator validator : ((UIInput)component).getValidators()) {
      if (validator instanceof LengthValidator) {
      final int min = ((LengthValidator)validator).getMinimum();
      final int max = ((LengthValidator)validator).getMaximum();
      if (min > 0) {
      newValue = newValue + " min" + min;
      }
      if (max > 0) {
      newValue = newValue + " max" + max;
      }
      //...
      }
      }
      }
      super.writeAttribute(name, newValue, property);
      }

      So far so good. However, we now want to move away from JSF validators and use JSR 303 validation on the beans (the idea is to reuse code for JSON REST interfaces).

      Does anybody know if there is there any way to get a list of the JSR 303 validators off a UIInput?