This discussion is archived
0 Replies Latest reply: Oct 26, 2012 12:31 AM by 970819 RSS

Retrieving JSR 303 validation/constraints on UIInput

970819 Newbie
Currently Being Moderated
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?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points