}
@Override
public void validate(final FacesContext context) {
context.getApplication().publishEvent(context, PreValidateEvent.class, UIValidateForm.class, this);
BeanManager manager = new BeanManagerLocator().getBeanManager();
manager.fireEvent(this, BEFORE);
Validator validator = null;
try {
validator = context.getApplication().createValidator(getValidatorId());
if (validator == null) {
throw new IllegalArgumentException("Seam UIValidateForm - Could not create Validator with id: ["
+ getValidatorId() + "]");
}
} catch (Exception e) {
throw new IllegalStateException("Seam UIValidateForm - Could not create validator with id [" + getValidatorId()
+ "] because: nested exception is:" + e.getMessage(), e);
}
Map<String, UIInput> components = getComponents();
try {
UIComponent parent = this.getParent();
validator.validate(context, parent, components);
} catch (ValidatorException e) {
setValid(false);
for (UIInput comp : components.values()) {
comp.setValid(false);
if (isShowFieldMessages()) {
context.addMessage(comp.getClientId(), e.getFacesMessage());
}
}
if (isShowGlobalMessages()) {
context.addMessage(null, e.getFacesMessage());
}
if(!isShowGlobalMessages() && !isShowFieldMessages()) {
log.warn("The form validation failed but neither 'showFieldMessages' nor 'showGlobalMessages' " +
"is true. The validation messages will be dropped.");
}
}
manager.fireEvent(this, AFTER);
context.getApplication().publishEvent(context, PostValidateEvent.class, UIValidateForm.class, this);
}