Reputation: 2896
I understand that the BindingResult is meant for validation errors relating to the form. However, what about business errors, for example:
public String bulkUpdate(@ModelAttribute form, BindingResult r) {
//do validation, extract selected issues to be bulk updated, etc.
//any form related, binding errors to be put in r
//this part
List<String> results = service.bulkUpdate(issues, newValues);
//where is it appropriate to put the results?
//from experience we just create a request attribute and put it there
request.setAttribute("bulkUpdateErrors", StringUtils.join(results, "<br>"))
//is there an similar generic structure like Errors?
}
And in the jsp:
<div id='info'>
<c:if test="${not empty bulkUpdateErrors}">
<spring:message code="bulk.update.warning" /> ${bulkUpdateErrors}
</c:if>
</div>
Is there a similar generic structure to put business errors?
Upvotes: 1
Views: 5671
Reputation: 9290
You can use separated object as you suggest or you can add business errors to Errors/BindingResult
. Personally, I usually put bussiness errors inside BindingResult because later is easier to show them in JSP/View. I don't know if there is any generic structure for this purpose.
Using r.rejectValue("property", "error.object");
, it's enough for that. Or if you want, global error can be registered calling r.reject("error.object");
Upvotes: 6