<a:form id="form"> <a:panel id="panel" header="Form" style="margin-bottom:10px;"> <a:messages id="messages" /> <h:panelGrid columns="3" cellpadding="5"> <a:outputLabel for="text1" value="Text 1:" /> <a:inputText id="text1" value="#{resetInputView.text1}" required="true" label="Firstname"> <f:validateLength minimum="2" /> </a:inputText> <a:message for="text1" /> <a:outputLabel for="text2" value="Text 2:" /> <a:inputText id="text2" value="#{resetInputView.text2}" required="true" label="Surname"/> <a:message for="text2" /> </h:panelGrid> </a:panel> <a:toolbar> <f:facet name="left"> <a:commandButton value="Submit" update="panel" actionListener="#{resetInputView.save}" style="margin-right:20px;" /> </f:facet> <f:facet name="right"> <a:commandButton value="Reset Fail" update="panel" process="@this" actionListener="#{resetInputView.resetFail}" style="margin-right:20px;" /> <a:commandButton value="Reset Tag" update="panel" process="@this" style="margin-right:20px;" > <a:resetInput target="panel" /> </a:commandButton> <a:commandButton value="Reset Code" update="panel" process="@this" actionListener="#{resetInputView.reset}" style="margin-right:20px;" /> <a:commandButton value="Reset Non-Ajax" actionListener="#{resetInputView.reset}" immediate="true" ajax="false" style="margin-right:20px;"> <a:resetInput target="panel" /> </a:commandButton> <h:commandButton value="Reset p:ajax" style="margin-right:20px;" > <a:ajax update="panel" resetValues="true" /> </h:commandButton> </f:facet> </a:toolbar> </a:form>
package com.jarch.showcase.view.misc; import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; import javax.faces.context.FacesContext; import org.primefaces.context.PrimeRequestContext; @ManagedBean public class ResetInputView { private String text1; private String text2; public String getText1() { return text1; } public void setText1(String text1) { this.text1 = text1; } public String getText2() { return text2; } public void setText2(String text2) { this.text2 = text2; } public void save() { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Data Saved")); } public void reset() { RequestContext.getCurrentInstance().reset("form:panel"); } public void resetFail() { this.text1 = null; this.text2 = null; FacesMessage msg = new FacesMessage("Model reset, but it won't work properly."); FacesContext.getCurrentInstance().addMessage(null, msg); } }