This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I've got a form controller with an onSubmit that processes the user submit:
I've got a ResultController, but I don't really know what to put in there. It's a SimpleFormController, but the view isn't a form, so is that what I should use? No formBackingObject method.
The ResultController bean in servlet.xml is:
There's nothing in myResult.jsp but some JSTL expressions:
So this runs, except the resulting page is blank. I know there is data in the Result object, because the log tells me so.
- I suspect this isn't the simplest way to do it, but i couldn't figure out how to use any of the non-form controller classes.
- I'd prefer to use a simpler controller class if that's the "best" way to do it, but at this point I'd also like to know what I'm doing wrong here. Maybe I need a formBackingObject method in MyResultController, but I couldn't figure out how to bind the model to the command object via the request parameters. Or even if that's what I'm supposed to do.
- I don't want my Result text to appear in the URL.
Help! Thank you!
P.S. The other parts of my setup are (I believe) pretty straightforward:
What is confusing me, si why do you need that second controller. You have one controller handling the request, then you return a ModelAndView object where you just add the view string and what you want in the model. The view string will direct it to the correct view jsp page, then you just have your jsp page display the data that is in the Model part of the ModelAndView.
I don't see the need to create a RedirectView object, or a Controller to handle that "redirect".
Now in your jsp page you just reference the bean in the Model. so I am assuming it might call it "result" , but it could be a different name. You can also specify the name in the
So the user goes to "editFoo.htm?fooId=123", edits data and submits the form.
In my (limited) experience, if I don't redirect, the URL for the myResult view will still be "editFoo.htm?fooId=123".
My requirement is that it say "myResult.htm". If I can do that with a "result" controller, all the better!
Also (and related), I updated my JSP and the onSubmit method of my editFoo Controller to reflect your suggestion to reference the bean in the model, but I can't seem to get the bean from the editFoo controller to the myResult.jsp view.
Joined: Feb 28, 2010
Further on the issue of simply using the result view directly instead of going through another controller: if the user goes directly to the result view (and the URL remains the same, i.e. "editFoo.htm?fooId=123"), a refresh by the user will resubmit the form.
Glenn Asbury wrote:Further on the issue of simply using the result view directly instead of going through another controller: if the user goes directly to the result view (and the URL remains the same, i.e. "editFoo.htm?fooId=123"), a refresh by the user will resubmit the form.
Any direction you can point me in?
Have you checked the name in the Model for the object you put there, and see if it is the same name you are using in your jsp page?
Also, May SPring 3.0 RESTful would work better for you.