No, that won't be sufficient. The errors.rejectValue(..) won't affect the flow. Apparently, once the validation has been done, the errors aren't looked after any more. We subclassed SimpleFormController and overrided processFormSubmission into:
Code:
protected ModelAndView processFormSubmission(
HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
throws Exception {
if (errors.hasErrors() || isFormChangeRequest(request)) {
if (logger.isDebugEnabled()) {
logger.debug("Data binding errors: " + errors.getErrorCount());
}
return showForm(request, response, errors);
}
else {
logger.debug("No errors -> processing submit");
ModelAndView modelAndView = onSubmit(request, response, command, errors);
// New code: look if the onSubmit has errors
if (!errors.hasErrors()) {
return modelAndView;
} else {
if (logger.isDebugEnabled()) {
logger.debug("onSubmit errors: " + errors.getErrorCount());
}
return showForm(request, response, errors);
}
}
}
Perhaps this should be included in the Spring framework, as business validation can happen in the onSubmit.