This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSF and the fly likes Problem in Reset button. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSF
Bookmark "Problem in Reset button." Watch "Problem in Reset button." New topic
Author

Problem in Reset button.

omkar patkar
Ranch Hand

Joined: Aug 25, 2005
Posts: 231
I am using the "Reset" commandbutton (<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> ). However i am facing problems in this component.

In the application, there is a form containing several fields like "combo box" , "text field" etc., When i click on the Reset button it works well provided i have NOT clicked on the "Submit" button before.

[B][/B]

However, lets say i have submitted the form once and i fill the form again with new details.... lets say now instead of submitting i want to reset then, ....when i click on reset it only clears the text field in the form, but not the other fields.

also lets say i have submitted the form, now the details i had filled were incorrect as per some validation in the database, and i refill the form and click on reset.... then non of the field gets cleared.

i don't know what could be the source of the problem. Can any one please help me in this respect??

Many thanks in advance.
Omkar !


Thanks and Regards
Omkar Patkar (SCJP 1.4)[url]http://javacollectionsnotes.blogspot.com[/url] | [url]http://omkar-myscjpexp.blogspot.com[/url]
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Do you clear the form after submitting?
Eugene Abarquez
Ranch Hand

Joined: May 18, 2006
Posts: 211
I haven't used type="reset" before, but when I want to clear the values in my textfields, I just bind the <h:commandButton> to a method in my backing bean and set the relevat properties to "" (empty String) or null.

JSF:


Backing Bean:

[ October 25, 2006: Message edited by: Eugene Abarquez ]

There's so much to learn in this industry, and not everybody has the necessary interest.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Rather use a DTO for each form and just do myForm = new MyForm() when you're about to reset. Imagine a form having more than 10 fields, this will produce a heap of nasty code in the bean.
Eugene Abarquez
Ranch Hand

Joined: May 18, 2006
Posts: 211
Originally posted by Eugene Abarquez:
[QB]I haven't used type="reset" before, but when I want to clear the values in my textfields, I just bind the <h:commandButton> to a method in my backing bean and set the relevat properties to "" (empty String) or null.

JSF:


Backing Bean:
omkar patkar
Ranch Hand

Joined: Aug 25, 2005
Posts: 231
Thank You Guys .... but i even thought of using the "clear" method ...but will it clear the Combo boxes completely or it will show the default value in the combo box ???
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
The default value is usually empty. But if you mean something like:


then this will just work.
omkar patkar
Ranch Hand

Joined: Aug 25, 2005
Posts: 231
Sorry Bauke, but i did not get you. In my case there is a dropdown or Combo box ...whose list of items is populated by a collection list. Now will the reset button clear my dropdown box completely and show nothing ( i.e., empty drop down box) or it will show the default value ?

I mean lets say, that the dropdown box shows four values :-

1) Porche
2) Ferrari
3) mercedez
4) TATA Safari

when the page loads for the first time the value seen by default in the dropdown box is say ... "Porche" ! Now lets say, that i select "Merecedez" from the dropdown .... but now, when, i click on "Reset", i want my dropdown to should show by deafult "Porche" ..... how can i make this possible ? ...any idea ???
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
It will just show the default values.
Eugene Abarquez
Ranch Hand

Joined: May 18, 2006
Posts: 211
Just equate the property to a value in your drop down that you want. So if your "default" value is "Porshe", equate the property to "Porshe".
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
But if he already has default values set, then those will just be used. Nothing special to change.
Ron De Leon
Greenhorn

Joined: Feb 14, 2006
Posts: 11
A quick solution, you can make the manage bean scope to request. This will automatically reset your form.

If you are using manage bean scope that is set to session, you can just re-initilize the object like Cars ford = new Ford().
omkar patkar
Ranch Hand

Joined: Aug 25, 2005
Posts: 231
Thank you guys ! .... while googling i cam across an article which suggests "erase()" ...but it was too vague ! ...does any one know ... how to use this method to erase the backing bean state ?

n e ideas ?

thanks in advance
Omkar
 
GeeCON Prague 2014
 
subject: Problem in Reset button.