I'm doing this to show errors from a view controller:-
Code:
protected abstract ModelAndView process(HttpServletRequest request, HttpServletResponse response,
Errors errors) throws Exception;
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception
{
BindException errors = new BindException("*", "*");
ModelAndView modelAndView = process(request, response, errors);
if (errors.hasErrors())
{
modelAndView.addAllObjects(errors.getModel());
}
return (modelAndView);
}
These methods are part of an AbstractViewController and provides errors that are bound to "*". The process method is what all sub-classes use for their logic and it now has an Errors object with which to add errors.
These errors can be displayed with the following:-
Code:
<html:hasErrors command="*">
<div align="center">
<div class="errorbox">
<img src='<html:rewrite href="image/reddot.gif"/>' width='16' height='16'>
<c:forEach var="error" items="${errors}">
<c:out value="${error}"/><br>
</c:forEach>
</div>
</div>
</html:hasErrors>
The code for my custom tag can be found in this thread (you can't use the <spring:hasBindErrors> tag for the same reasons as the original poster there):-
http://forum.springframework.org/showthread.php?t=18978
Bob