• 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

calling reset on the form bean

 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
What is the syntax to call the reset method on my formBean from the Struts <html:reset>? It seems oddly Escher-esque. How do I specify it so Struts will reflect and get the name of that formBean (possibly one of many on the document) and call it? Is it something that I have to do manually with an onClick event and a custom javascript function that somehow calls the formBean? tia
 
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 <html:reset> tag does not call the reset method on the ActionForm. The two have nothing to do with each other. The <html:reset> tag produces an HTML <input type="reset"> tag, which renders an reset button. A reset button causes any input fields to revert to their original values.

The reset method on an ActionForm is called automatically by Struts after the ActionForm is instantiated, but before it calls the setters.
 
Chris Pat
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Merrill
Yes, I know that and I have changed the scope on my action to be request so it resets and that works. However I want the reset button to work as implied; when I click on it nothing happens. How do I code the syntax, I assume in the onClick, to call the reset on the formBean whenever it is clicked?

Originally posted by Merrill Higginson:
The <html:reset> tag does not call the reset method on the ActionForm. The two have nothing to do with each other. The <html:reset> tag produces an HTML <input type="reset"> tag, which renders an reset button. A reset button causes any input fields to revert to their original values.

The reset method on an ActionForm is called automatically by Struts after the ActionForm is instantiated, but before it calls the setters.

 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Yes, I know that..."

Do you? The reset button is 100% client side. It does not submit your form, interact with any of your actions, or call methods on your "formBean". All it does is reset all the form fields on your page to what they were when the page was first displayed. Note that this does not mean that it will clear all the fields or set them back to some set of predefined default values. In my opinion the reset button is just about the most useless thing in the html specification and I don't see any reason to use it.

- Brent
 
Chris Pat
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Well I guess not. By scope-ing the Action to request, it clears form between submissions. However I need to have the Reset button work. Does that mean I have to fully write a javascript funtion client site and attach it to the html:reset tag? Is there nothing more automated I can use? Cant I use a Validator and have it work to reset the Reset button onClick.

Originally posted by Brent Sterling:
"Yes, I know that..."

Do you? The reset button is 100% client side. It does not submit your form, interact with any of your actions, or call methods on your "formBean". All it does is reset all the form fields on your page to what they were when the page was first displayed. Note that this does not mean that it will clear all the fields or set them back to some set of predefined default values. In my opinion the reset button is just about the most useless thing in the html specification and I don't see any reason to use it.

- Brent

 
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

Originally posted by Chris Pat:
However I need to have the Reset button work.


The HTML reset button does "work" according to it's limited specified functionality. The trouble is that your definition of "works" seems to be different than that. If you write your own JavaScript code, you are completely in control of what "works" means or doesn't mean, so that may be your best option.

Rather than using <html:reset>, I would use <html:button>. Since you apparently have no use for the original functionality of the reset button, there's no point in using it. The button tag was specifically designed for use with JavaScript. It only does whatever you cause the onclick event to perform.

Sometimes I put a button on a form with the label "reset" when the function I want this button to perform is to reset the values of all input fields to the value they currently have in the database. For this function, the tag I use is <html:cancel>.

This produces a submit button that has some special meaning for Struts. First of all, it tells Struts not to run validation. That is, it doesn't call validate on your ActionForm, nor does it perform framework validations. Secondly, it sends a flag to the Action class. You can call the Action class method isCancelled to determine whether the cancel button was pressed, or whether a regular submit button was pressed. I then put logic in my Action class such that if isCancelled is true, I retrieve the values from the database and forward to the calling JSP.

If this is the type of thing you're looking to do, great. If not, it sounds like an <html:button> with an onclick event calling your own JavaScript function is your best bet.

One other note: If you're using Struts 1.2.9 or above, you must specify cancellable=true when you define the action path in struts-config.xml in order to use the cancel button.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic