Help coderanch get a
new server
by contributing to the fundraiser
  • 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

Simple form: inputText does not reset

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am new to JSF and I have got working a simple form, that takes input from user by inputText and after I submit the form - the data will be saved to a database.

The navigation goes like this, that after the form is submitted, the same page and same form will be showed. My problem is, that after the submit, when page is reloaded, the input fields are filled with information I just submitted. I want them to be empty, just like they were from the first request.

I am sure for that, there is a simple solution, but I can't find it.


contacts.jsp:


faces-config.xml:


my.package.ContactForm.java is just simple form bean with action-methods and properties: String firstname, lastname and email.


Thanks.
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anybody?
 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<td><h:inputText value="#{contactForm.firstname}" id="text1"/>
</td>
here i defined an id for your textfield so that it can be referenced from your backing bean. Now get this component in the action method of your button and clear it.

like

getText1.setValue("");

I am not sure if this is the right approach.

Thanks,
 
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rajeev Ravindran:
<td><h:inputText value="#{contactForm.firstname}" id="text1"/>
</td>
here i defined an id for your textfield so that it can be referenced from your backing bean. Now get this component in the action method of your button and clear it.

like

getText1.setValue("");

I am not sure if this is the right approach.

Thanks,


contactForm.setFirstname(null); would do the trick.
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic