I'm trying to write my first web application using Spring MVC and I've got a question about the pattern that I should use.
I've got a situation where I need three pages. The first two contain forms. The last is a success/failure message and a summary of what was done. The first form gives the user a choice. Depending on their choice, the second form may be skipped (i.e., there's already enough information to take action and skip to the last page).
Each of the pages have some text that comes from the database, so I need them all to have custom controllers (or at least something more complex than the UrlFilenameViewController) to populate the model.
So, what I was trying to do was create three controllers, one for each page. I set out trying to use a AbstractFormController for the first two pages, but I've run into a hurdle.
I want the controller for the third page (the status/summary page) to gather the information needed to render the view. In the case that the first controller (on submission) detects that the second page can be skipped, I want to go straight to the third controller.
What it appears is supported and easy is to go to a view (the third JSP) from there. Well, since that's a JSP, the model won't be populated if I go straight to it. I need to hit the controller. I don't really want to replicate that model-population code in both the first and third controllers.
So, I have a few options that I can see here.
1. I can just use the RequestDispatcher to forward to the third controller. This is what I'm doing now and it looks ugly.
2. I can write a new View (I think) that forwards to the named controller and return "new ModelAndView(new ForwardView(url))" from the first controller.
What I'd like to do is find a ViewResolver that will forward to another controller if there's one with such a name. Then I could configure that resolver to run first. If it can't map the string to another controller, I can fall back on the InternalViewResolver to try to render it with a JSP.
That would also allow me to use all the stock controllers that allow you to set the views through their properties in the XML to actually forward to another controller (SimpleFormController's successView comes to mind).
So, am I making this really hard somehow? I don't feel like it should be hard. I feel like I'm just missing something obvious.