File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes clearing HTML form fields after return from struts validation with errors 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 "clearing HTML form fields after return from struts validation with errors" Watch "clearing HTML form fields after return from struts validation with errors" New topic
Author

clearing HTML form fields after return from struts validation with errors

Kareem Gad
Ranch Hand

Joined: Aug 06, 2001
Posts: 89
This must be really simple but I just can't get the hang of it.

I have a normal struts form that performs the validate method, if there are errors it returns back to the same jsp page that has the HTML form. Struts being lovely also pre-populates the fields with the data from the Struts Form object now in session.

I need to click on the "reset" or "clear" button on that form and be able to clear out all the fields of the form just like standard HTML reset behaviour.

When I try that the fields that were pre-populated to the HTML form do not clear out. What can i do to overcome this, other than the manual way of having a javascript that can go and clear each and every field in the form manually.

Consider a form with just too many fields to do that !

I hope this has been addressed by someone before..


<b><i>KaReEm</i><br /><ul type="square"><li>SCJP-Free Range Web Developer <br /></ul></b>
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

Kareem,
I can think of two ways:
1) Use Javascript to loop through the form fields instead of hard coding each one.
2) Redirect to the Struts action that created the blank form in the first place.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
kapil patel
Ranch Hand

Joined: Sep 30, 2005
Posts: 33
Hi,

I have similar problem. I am reseting form using javascript. However, it displays again to all previously entered field values.

In my case, I am populating some selection options using another action. And submit jsp page for another action.

thanks in advance
kapil patel
Christian Nash
Ranch Hand

Joined: Jan 17, 2006
Posts: 107
Hi Kareem,

From what you say I'm guessing there are 2 forms and your fields are distributed between these forms.

in the javascript you can use:

for the upper form if the elements are all text fields.
Similarly for the lower form you can use



- Christian
Kareem Gad
Ranch Hand

Joined: Aug 06, 2001
Posts: 89
Hi all,

Thanks for your suggestions. I have come around resolving this using the approach suggested by Jeanne of redirecting to the action that created the form blank in the first place.

Ofcourse needing to handle clearing the session appropriately when doing so.

-K
 
Don't get me started about those stupid light bulbs.
 
subject: clearing HTML form fields after return from struts validation with errors
 
Similar Threads
Clearing of Struts forms on reset
Clear and Reset Functionality in struts
My First Struts App
Problem Resetting Fields
Regarding "html: reset " button