I have multiple forms, where I have mandatory fields and optional fields.
To submit such a form I require the validation on the required-attribute to be exe
if you want to skip validation when click on button then easly add parameter to button where you want to skip it. Example:
Then in validator you can read this parameter and if it is true then skip it:
@FacesValidator("com.validators.MyValidator")
public class MyValidator implements Validator{
public void validate(FacesContext ct, UIComponent co, Object obj) throws ValidatorException {
if(!continueValidation()){
return;
}
// validation process
}
protected boolean continueValidation() {
String skipValidator= FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("skipValidator");
if (skipValidator != null && skipValidator.equalsIgnoreCase("true")) {
return false;
}
return true;
}
}