Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

clearing HTML form fields after return from struts validation with errors

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
author & internet detective
Posts: 40796
828
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Kareem Gad
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic