How To Reset a Form (Not as easy as you would think)?
843842Jun 7 2004 — edited Aug 6 2008Hi All,
I'm unable to get a form to reset its value when using a commandButton that has immediate set to true.
I've got a simple little jsf page that has a form and a datatable. The form is bound to an object in a class I'm using to handle the view, the datatable is bound to a dataModel from the same handler class. The functionality I have is quite simple:
a user clicks on a commandLink in a row of the datatable
the corresponding object is loaded into a "currentObject" property of the handler class
the form fields are mapped to the "currentObject" property of the handler.
The user may update or reset the form.
The goal is to have the reset commandButton set the "currentObject" property of the handler class to null (or a new, unpopulated object) so that the fields of the form are set to blank again on render. This works fine as long as I don't use immediate="true". When I do use the immediate=true attribute, the "currentObject" variable is, indeed, set to null, but the form still renders with the old "currentObject" values in it!!
I have to use immediate="true" because there is validation going on for the form that I want to avoid.
If I use a commandButton type="reset", the fields are not cleared because the reset functionality of the browser (ie6 and firefox) resets the fields to the values they were at the time the form was displayed--the very values I wish to totally remove!
This seems like such a common, simple thing to do. What am I missing?
Thanks,
John