aspose file tools*
The moose likes Struts and the fly likes Saving the form before navigating to some other page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Saving the form before navigating to some other page" Watch "Saving the form before navigating to some other page" New topic
Author

Saving the form before navigating to some other page

Rohithaksha Kalluraya
Greenhorn

Joined: Jan 12, 2010
Posts: 10
I am using struts framework.

I have page1, page2, etc.
On page1 there is a link to navigate to page2. Also there is a form on page1 that user fills in and submits. If user enters details on this form and clicks on the page2 link without submitting the form I would like to prompt the user whether he wants to save or not. If user says yes, I need to save the form and stay in the same page. If user says no, I need to proceed to next page without saving it. I want to do this action in the web-tier.

Thanks!

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

Rohithaksha Kalluraya wrote:If user says yes, I need to save the form

What do you mean by save the form?? You can use a javascript confirm dialog to prompt the users choice of yes or no. This confirm dialog can be shown on the onclick event of the hyperlink. If the user chooses to navigate to the other page, you'll return true from javascript. If user wants to stay at the page, then you'll return false from the javascript, when the onclick event of a hyperlink returns false, the browser doesn't follows the hyperlink...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Rohithaksha Kalluraya
Greenhorn

Joined: Jan 12, 2010
Posts: 10
Thank You for the reply!

Let me rephrase the question. I have a page "page1", that page has a form (where user can enter details, ex., account creation form). I don't want to do a frontend validation using javascript, but would like to use MVC framework that validates and remembers the user input even if the user does not submit that form. Closest example of this I can think of is, gmail that keeps saving the composed emails. Even if user loses connections or forgets to send the email, that email will be saved and can be retrieved from Drafts folder.

Thanks again!
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

What gmail does is that it keeps making ajax requests at regular time intervals and sends all the form data (the email in case of gmail) to a specific servlet/struts action on the server which saves the values somewhere (in drafts folder in case of gmail). That's what you need to implement too. The exact implementation details will depend on your requirements...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Saving the form before navigating to some other page