This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Error Handling in MultiActionController

Aug 19th, 2004, 02:15 PM

Is there a recommended way of error handling when using the MultiActionController. Since this class doesnt really expose the command object paradigm, I was wondering what approach might be used to create errors and redisplay back on the submitting page. I noticed that the BindException takes a command object in the constructor to represent the command object, which is not available. I would like to make use of the Spring taglibs in the JSP to display errors because of the ease of use.

Comment

Thanks for that code snippet. That definately got me going in the right direction, but I wanted to be able to handler things similarly in the Spring MVC whether I was using a Command-bound Controller (like SimpleFormController) or an unbound Controller (like Controller or MultiActionController).

Here is what I have come up with so far:

I created an implementation of org.springframework.validation.Errors called UnboundException (similar to BindException) that is bound to the HttpServletRequest instead of a Command object. I can now use JSPs the same way, whether in a command-bound or unbound scenario with the same <spring:bind> tag paradigm and the form fields are re-populated from the request if I re-display the same page (in case of error). I am not finished testing this paradigm yet, but the results so far are very promising...

One of the things the Spring Web Framework stresses is flexibility and this is a great example. I suppose the next step could be the creation of an AbstractUnboundController that makes use of this exception, has a "successView" without having "commandName" or "commandClass" parameters...