Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Saving the form before navigating to some other page

 
Rohithaksha Kalluraya
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Rohithaksha Kalluraya
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic