This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Spring and the fly likes How do I create a basic confirmation page with dynamic content? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How do I create a basic confirmation page with dynamic content?" Watch "How do I create a basic confirmation page with dynamic content?" New topic
Author

How do I create a basic confirmation page with dynamic content?

Glenn Asbury
Greenhorn

Joined: Feb 28, 2010
Posts: 7
So I'm done banging my head against my monitor:

What is the simplest way to display a confirmation web page?

For example, a user submits a form that updates the database. Upon success, I want to redirect the user to a very basic view that displays some text info:

- what you did worked (or did not work)
- here's where you can go now: [link] or [link] or [link].

The text displayed would depend on what the user did, of course.

I can't figure out how to do this.

Here are the parts:

I've got a Result class with two String fields:



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.

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.

Grrr...

Help! Thank you!

--Glenn

P.S. The other parts of my setup are (I believe) pretty straightforward:

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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

model.addObject("nameOfBean", bean);

then in the jsp

${nameOfBean.somePropertyOfBean}

And that is all.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Glenn Asbury
Greenhorn

Joined: Feb 28, 2010
Posts: 7
Thanks, Mark. Fair question.

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.

Thanks again,

Glenn


Glenn Asbury
Greenhorn

Joined: Feb 28, 2010
Posts: 7
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?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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.

Mark
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How do I create a basic confirmation page with dynamic content?
 
Similar Threads
Spring MVC Request Mapping
Configure success view to be the same form view
helloworld spring mvc
Spring MVC question
Spring problem (SimpleFormController)