• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Problem in Reset button.

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you clear the form after submitting?
 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The default value is usually empty. But if you mean something like:


then this will just work.
 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will just show the default values.
 
Eugene Abarquez
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But if he already has default values set, then those will just be used. Nothing special to change.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic