aspose file tools*
The moose likes Struts and the fly likes Avoiding form resubmission Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Avoiding form resubmission" Watch "Avoiding form resubmission" New topic
Author

Avoiding form resubmission

sri kris
Greenhorn

Joined: May 23, 2008
Posts: 10
hi,I have a form where i have 2 textboxes,1 dropdown and a submit button. when i select an option from the dropdown, values for the other fields are fetched from DB and displayed in the form. i am doing this through javascript by submitting the form once the option from dropdown is selected. the user can change the values that are fetched from the DB and submit again using submit button. however by clicking the browsers bcak button user should not submit the form using submit button. ie user should not resubmit(by clicking on the submit button provided) the form by coming thrpugh the browsers back button. how to handle this.
sri kris
Greenhorn

Joined: May 23, 2008
Posts: 10
can anyone suggest any idea??
Dishpal Bhaluja
Ranch Hand

Joined: Dec 30, 2007
Posts: 96
Method i suggest is to create a session variable and based on its value disable or enable the button.
Dishpal Bhaluja
Ranch Hand

Joined: Dec 30, 2007
Posts: 96
You can use struts logic tag to check whether variable present in the required scope
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Two textboxes and 1 dropdown menu. When you select an option, the form is submitted and the results of a database query populate the values of the two textboxes.

There should be two forms here, not one. The first form handles the selecting of an option and the retrieval of data from the database. The second form handles the editing of data and saving of revised data.
Dishpal Bhaluja
Ranch Hand

Joined: Dec 30, 2007
Posts: 96
Clark why we need two forms here;Just one form and an ajax call for drop down will do the rest.Cant we?
sri kris
Greenhorn

Joined: May 23, 2008
Posts: 10
why to have two fomrs?? cant we do it in a single form itself??
anyway can you please explain how it could be done using two forms as well?
Dishpal Bhaluja
Ranch Hand

Joined: Dec 30, 2007
Posts: 96
Yes,It can be solved in one form itself.

On drop down selection call your action class's function through javascript and pass on the parameter you got to that function.From there do your business logic and return the results back as an xml/json response and output the result back to your jsp page.

Simple solution:Use Ajax.

Refer Book:Struts complete Reference.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
why to have two fomrs?? cant we do it in a single form itself??


It is unclear why you even want to do it in a single form. There are two server actions going on here, not one. There are two database actions here, not one. So, why try to do it with one form?

You still need either two Actions or a single Action that handles different requests.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Avoiding form resubmission
 
Similar Threads
assign dropdown selected value to a java variable
Dropdown Selected returning unexpected value on submit.
Submitting hidden values on the form with onSelect option
How to submit through a dropdown menu.
JSF Questions