• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Common Functionality in all the pages.

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
please buy my thing and then I'll have more money:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic