• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Glenn Asbury
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
reply
    Bookmark Topic Watch Topic
  • New Topic