If you mean my hack here comes the code for it.
Note: My model is named "formModel". I only except ignoring of the validation on the event with the id "next". So not all events can skip validation. For each controller AND state you have to implement the function with its name. (In this example validateShow is called for the state show of and the controller MyController. If you use different states AND different controllers you have to implement each combination. In my case I have the same state in 10 different controllers thanks to subflows.)
I hope this helps!
Code:
@Component
public class FormModelValidator extends DefaultBeanValidator {
private String eventID;
/*
* This function sets the eventid global out of the context
*/
private void preValid(ValidationContext context) {
eventID = context.getUserEvent();
}
// FIXME Hack of the validation cause the eventId is not given
public void validateShow(MyController obj, ValidationContext context) {
preValid(context);
}
@Override
public void validate(Object obj, Errors errors) {
// is the object to validate an instance of my controller
if (obj instanceof MyController) {
// is the event set to be ignored and the eventid is "next"
if (((MyController) obj).isIgnoreValidate() && eventID!=null && eventID.equalsIgnoreCase("next")) {
// do nothing so no validation is done
return;
}
}
// we call the validation in any other case
super.validate(obj, errors);
}