In my MVC controller I have a handler method with a signature:
public void myAction(ActionRequest request, ActionResponse response, Model model) {...}
And in this method I check if some submitted data is okay. If it's not valid, I want to set an error. Currently I do it this simple way:
model.addAttribute("operationStatus", "error");
model.addAttribute("operationMessage", "a lot of things went wrong");
and in the view JSP:
<c:if test="${requestScope.operationStatus == 'error'}">
<div class="msg-error">${requestScope.operationMessage}</div>
</c:if>
Surely there has to be a better way to handle errors in Spring Portlet MVC. Note that I need to display the error messages in different places, not only in <form>
tag.
So how should I handle errors?