Linconnue55
Linconnue55

Reputation: 187

Reset input fields in primefaces

I have a Dialog to input details. At the first time , InputText are empty. But from the second input, InputText maintain the previous value.

This is my code :

     <p:commandButton id="showDialogButton1" type="button" value="add" onclick="dlg1.show()" update="firstname1"/>
     <p:dialog id="dialogAjout" header="add department" widgetVar="dlg1" resizable="false">  
          <h:panelGrid columns="2" style="margin-bottom:10px">  
                <h:outputLabel for="firstname1" value="Libellé :" />  
                <p:inputText id="firstname1" value="#{departementBean.departement.libelleDepartement}" />
          </h:panelGrid>  
          <p:commandButton id="submitButton1" value="Valider" oncomplete="dlg1.hide();" action="#{departementBean.addDept()}" update="tabView"/> 
     </p:dialog>

How can I resolve this, please !!

Upvotes: 3

Views: 39516

Answers (5)

estevamdf
estevamdf

Reputation: 23

I solved this question thus

<p:dialog header="myDialog" widgetVar="dlg1" minHeight="40">
   <h:outputLabel for="fild1" value="Fill the field" /> 
   <p:password id="fild1" value="#{myBean.attribute}" required="false" label="Field" redisplay="false" /><br />
   <p:commandButton action="#{myBean.method()}" value="Send" oncomplete="dlg1.hide()" update="field1" />
</p:dialog>

When I used the attribute update="field1" of p:commandButton. The value of field p:password will empty after submitting the form.

I tried do the suggestion of Dani but my attribute going empty when I submitted my form and not stayed empty after submit

Upvotes: 0

Dragos Bulugean
Dragos Bulugean

Reputation: 349

You can use this primefaces component: http://www.primefaces.org/showcase/ui/misc/resetInput.xhtml Regarding dialogs in general: don't put them inside forms. Have this instead: <p:dialog><h:form>... Regarding update="" values, if your appendToBody is true, put a colon in front of the id (that means it`s in another form).

Upvotes: 7

sagar Borage
sagar Borage

Reputation: 61

You should use the following code:

<h:commandButton value="Reset" style="margin-right:20px;">
    <p:ajax update="registrationForm" resetValues="true" />
</h:commandButton>

Upvotes: 6

user3092514
user3092514

Reputation: 61

Add resetValues="true" to your commandButton

<p:commandButton resetValues="true" action="#{departementBean.prepareDialog}"  id="showDialogButton1" type="button" value="add" oncomplete="dlg1.show()" update=":dialogAjout"/>

Upvotes: 5

Daniel
Daniel

Reputation: 37061

modify you open button like this : open dialog in oncomplete and before that update it by adding its id to update attribute and add action method to do the server side logic to actually init the dialog fields (populate / reset)

<p:commandButton action="#{departementBean.prepareDialog}"  id="showDialogButton1" type="button" value="add" oncomplete="dlg1.show()" update=":dialogAjout"/>

b.t.w it looks like your dialog located inside your form together with your opening button , this is a "bad practice" move your dialog away from that form and place a new form inside the dialog , e.g <p:dialog><h:form> ...

Upvotes: 4

Related Questions