• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to save state of a form.

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a sample page that shows how to do it.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic