ResetInput
Input components keep their local values at state when validation fails. ResetInput is used to clear the cached values from state so that components retrieve their values from the backing bean model instead.
Source
<h:form id="form">
<p:panel id="panel" header="New User" style="margin-bottom:10px;">
<p:messages id="messages" />
<h:panelGrid columns="3">
<h:outputLabel for="firstname" value="Firstname: *" />
<p:inputText id="firstname" value="#{pprBean.firstname}" required="true" label="Firstname">
<f:validateLength minimum="2" />
</p:inputText>
<p:message for="firstname" />
<h:outputLabel for="surname" value="Surname: *" />
<p:inputText id="surname" value="#{pprBean.surname}" required="true" label="Surname"/>
<p:message for="surname" />
</h:panelGrid>
</p:panel>
<p:commandButton value="Submit" update="panel" actionListener="#{pprBean.savePerson}" />
<p:commandButton value="Reset Fail" update="panel" process="@this" actionListener="#{pprBean.resetFail}" />
<p:commandButton value="Reset Tag" update="panel" process="@this" >
<p:resetInput target="panel" />
</p:commandButton>
<p:commandButton value="Reset Code" update="panel" process="@this" actionListener="#{pprBean.reset}" />
<p:commandButton value="Reset Non-Ajax" actionListener="#{pprBean.reset}" immediate="true" ajax="false">
<p:resetInput target="panel" />
</p:commandButton>
</h:form>
package org.primefaces.examples.view;
import org.primefaces.context.RequestContext;
public class PPRBean {
private String firstname;
private String surname;
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public void reset() {
RequestContext.getCurrentInstance().reset("form:panel");
}
public void resetFail() {
this.firstname = null;
this.surname = null;
FacesMessage msg = new FacesMessage("Model reset, but it won't work.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
