Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to save state of a form.

 
Kim Chew
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello folks,

I have a scenario like this,
Page A : Some text boxes and check boxes.
Link to Page B.
A "Save" and a "Cancel" button.

Page B : Some text boxes and check boxes.
A "Save" and a "Cancel" button.

My question is like this, if the user typed in something in the text boxes
on Page A, then clicked the link to Page B. In Page B, the user clicked
the "Cancel" button which bring him back to Page A. How do I preserve the
changes the user made in Page A (Without using the "back" button,of course)?

Thanks in advance!

Kim
 
SuprajaY Yasoda
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will be better to insert the values into the database once Save button is pressed. On clicking of Cancel button user will see the data fetched from database
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way I know to do this would be to change the link so that it calls a javascript function using the onclick event, or changing the link to "javascript:myfunction()". In that function put code that changes the action of the form and submits it. A link does not preserve the state of the form before loading another page, while a form submission does.

So, you might create a new action mapping that simply forwards to page B. Then, in your javascript function, change the form's action property to the new action mapping and submit the form. Struts will then populate your form bean with whatever the user entered before clicking the link. If the user goes back to Page A, the fields will be populated.
 
Deepak Tewari
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I too agree with Merrill Higginson the thing u can do is on the click of the button call a java script that submits the page and in the action class save the data that is the form obtained, in the session if u dont want to save the data parmenantly ie (submit of the page) other wise submit the page hence since the form is saved in the session u can populate the page again on coming back to the page again.
 
Kim Chew
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Merrill, thank you very much for your response.
I am not very well versed in Javascript, so while I understand the
mecahnism but I don't know how to "change the form's action property to the
new action mapping and submit the form." in the java script function.

So please allow me shamelessly to ask for a example snippet.

Many thanks.

Kim
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a sample page that shows how to do it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic