wood burning stoves 2.0*
The moose likes Struts and the fly likes Common JSP/Action displaying confirmation details Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Common JSP/Action displaying confirmation details" Watch "Common JSP/Action displaying confirmation details" New topic
Author

Common JSP/Action displaying confirmation details

Michael Lok
Greenhorn

Joined: Apr 01, 2005
Posts: 3
Hi folks,

I'm in the midst of developing an application which requires the fields of any form to be re-displayed to the user before the actual Action mapping is called. I've not been able to determine a way on how to achieve this feature except for storing the source form object in session.

Has anyone done this before or is there such thing built-in in Struts (don't think so; but worth a try ).

Thanks in advance.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you use the <html:form> tag, the action mapping specified in the "action" attribute will be invoked when the form is submitted. There's no way around this.

You can use javaScript to do all kinds of things before submitting the form, such as popping up an "are you sure?" message, but once the form is submitted, the action mapping is going to be called.

I generally try to resist the urge to question why someone wants to do something, but I'm really having a hard time understanding why this would ever be a requirement. The normal flow of a struts application is to cause execute() method of the Action class to be called when the form is submitted. Once in the Action class, you have a lot of options. You can certainly redisplay the page without saving the data to a database if you want. I just don't see why it would ever be necessary to bypass the Action class.

If you really want to do it, though, you might want to look at putting some logic in the validate() method of your ActionForm to always reject the data the first time and accept it the second time.


Merrill
Consultant, Sima Solutions
Michael Lok
Greenhorn

Joined: Apr 01, 2005
Posts: 3
Coming from a financial company, the current internet banking system has the basic feature whereby ALL form submissions are followed by a confirmation page where all user submitted values are re-displayed after validation. This is to protect the user from doing anything odd and to basically cover our tracks; so to speak.

Sometimes there's some processing to be done before displaying the confirmation page e.g. calculating the actual xfer amount having obtained the cross currency rate.

That's the main reason for this feature to be placed in this application.

Anyway, thanks for your input. I'll give some thought to tweaking the validate() function in the form class.
[ January 11, 2006: Message edited by: Michael Lok ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
if there is calculation to be done prior to redisplaying the confirmation page, that's all the more reason to do it in the Action class. It's made for that type of thing. As I mentioned, the Action class does not have to save to a database. It can redisplay a confirmation page. I would imagine logic something like this in your execute() method.

 
wood burning stoves
 
subject: Common JSP/Action displaying confirmation details