wood burning stoves 2.0*
The moose likes Struts and the fly likes Common Functionality in all the pages. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Common Functionality in all the pages." Watch "Common Functionality in all the pages." New topic
Author

Common Functionality in all the pages.

Clarice Doe
Greenhorn

Joined: Dec 24, 2004
Posts: 21
We use Struts framework in our application that has lot of JSP pages.
What ever the user enters in those pages are saved in the session and at the last page, the user has an option to save everything to the database.

Now, we have to provide a Save button on every page, so that the user can save the data entered in that screen (and in the previous screens) to the database.

What is the best approach to acheive this? I was thinking of creating a separate page containing this Save button and including it in all the pages (lets call it as Save.jsp). But there are 2 issues

i) When I click the Save button in Save.jsp, I don't want the form in the Save.jsp to get submitted, rather I want to submit the contents of the enclosing page.
ii) The enclosing page has some Javascript validations, and those validations should happen when I click on the Save button in the Save.jsp

Or is there any better way to get this done?

Thanks
Horatio Westock
Ranch Hand

Joined: Feb 23, 2005
Posts: 221
Hi,

So, basically your problem is a general problem of having more that one submit button on a form.

You could look at LookupDispatchAction to solve this. There is an atricle here that describes something similar.

Article on jguru
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If I'm understanding you correctly, the real problem is that before you had only one submit button that says essentially "Continue to the next page without saving to the database", and now you want to keep this function and also add another that says "save this page and all previous in the database and return to this page".

I'm assuming that you already have created an action for each case, which I'll arbitrarily call "next.do" and "save.do". As I see it, the best solution is to change both submit buttons to simple buttons with onclick events that call a javascript function. The javascript function will simply perform any validation, change the action attribute of the form, and then submit it.

Here is an example javascript function that you might want the onclick event of the button to call:

This assumes you have already written a validate() function that returns true if the page passes the validations, and false if it doesn't.

The save button onclick event would call submitForm('save.do') and the next button onclick event would call submitForm('next.do').

If you want to put the new submit button in jsp include file, that's fine, but the function would be the same either way.

Since you want the save.do action to return to the page that called it, you will probably want to put a hidden field on each page identifying the calling page, so that the logic in your save action can forward to the appropriate page.

Good luck

Merrill
[ March 03, 2005: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
 
 
subject: Common Functionality in all the pages.