title: Clearing form fields after invalidation JSF
body: <p>Ok i have the following problem: In my web app i have the CRUD all one page via dialogs controls of Primefaces. In the new dialog i have some validators. For example: when a user does not fill the necessary fields for form submission obviously the form doesn't submit. But when i close de New dialog and open it up again, the validation messages are still there! How can i get rid of this? I want a fresh new page (without accumulated validation errors) every time a dialogs open up! How that can be done?</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:p="http://primefaces.org/ui"
              template="./../../resources/templates/baseTemplate.xhtml"&gt;
  
  &lt;ui:define name="content"&gt;
      &lt;f:view id="vRoot"&gt;
          &lt;p:fieldset legend="Gerenciar público"&gt;
              &lt;h:form id="frmPublicos"&gt;
                  &lt;!-- Exibição de mensagens gerais --&gt;
                  &lt;p:growl id="gMessages" sticky="false" globalOnly="true" /&gt;
  
                  &lt;!-- Exibição da lista de públicos --&gt;
                  &lt;p:dataTable id="dtPublicos" 
                               value="#{publicoBean.lstDataTablePublico}"
                               paginator="true" rows="5" 
                               rowsPerPageTemplate="5,10"
                               paginatorPosition="bottom"
                               paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                               var="atual"&gt;
                      &lt;!-- Every time dialog opens validation messages should be cleaned --&gt;
                      &lt;f:facet name="header"&gt;
                          &lt;p:commandButton id="cbViewNovo" 
                                           value="Novo" type="button" 
                                           styleClass="cbViewNovo" 
                                           onclick="dlgNovo.show();"
                                           update=":dlgNovoPublico"
                                           process="@this"&gt;
                              &lt;p:resetInput target=":dlgNovoPublico"/&gt;
                          &lt;/p:commandButton&gt;
                      &lt;/f:facet&gt;
                      &lt;!-- Colunas de edição e exclusão --&gt;
                      &lt;p:column&gt;
                          &lt;f:facet name="header"&gt;
                              &lt;h:outputLabel value="Editar"/&gt;
                          &lt;/f:facet&gt;
                          &lt;p:commandButton id="cbViewEditar"  
                                           image="ui-icon-pencil" 
                                           title="Editar"
                                           update=":frmEditar:pEditarPublico"
                                           oncomplete="dlgEditar.show();"&gt;
                              &lt;f:setPropertyActionListener value="#{atual}" target="#{publicoBean.publicoSelecionado}" /&gt;
                          &lt;/p:commandButton&gt;
                      &lt;/p:column&gt;
                      &lt;p:column&gt;
                          &lt;f:facet name="header"&gt;
                              &lt;h:outputLabel value="Excluir"/&gt;
                          &lt;/f:facet&gt;
                          &lt;p:commandButton id="cbViewExcluir" onclick="dlgExcluir.show();" 
                                           icon="ui-icon-close" title="Excluir"&gt;
                              &lt;f:setPropertyActionListener value="#{atual}" target="#{publicoBean.publicoSelecionado}" /&gt;
                          &lt;/p:commandButton&gt; 
                      &lt;/p:column&gt;
                      &lt;p:column&gt;
                          &lt;f:facet name="header"&gt;
                              Nome
                          &lt;/f:facet&gt;
                          &lt;h:outputLabel id="olViewNomePublico" value="#{atual.nmePublico}"/&gt;
                      &lt;/p:column&gt;
                      &lt;p:column&gt;
                          &lt;f:facet name="header"&gt;
                              Tipo de público
                          &lt;/f:facet&gt;
                          &lt;h:outputLabel id="olViewTipoPublico" value="#{atual.tdTipoPublico}"/&gt;
                      &lt;/p:column&gt;
                  &lt;/p:dataTable&gt;
              &lt;/h:form&gt;
  
              &lt;!-- Caixa de diálogo de inclusão --&gt;
              &lt;p:dialog id="dlgNovoPublico" 
                        widgetVar="dlgNovo" 
                        modal="true" 
                        header="Novo público"
                        resizable="false"&gt;
                  &lt;h:form id="frmNovo"&gt;
                      &lt;p:panel id="pNovoPublico"&gt;
                          &lt;p:messages id="mNovoMessages" redisplay="false" /&gt;
                          &lt;p:panelGrid columns="2"&gt;
                              &lt;p:outputLabel id="olNovoNomePublico" value="Nome:" for="itNovoNomePublico"/&gt;
                              &lt;p:inputText id="itNovoNomePublico" value="#{publicoBean.nome}" required="true"
                                           requiredMessage="Digite o nome do público."/&gt;
  
                              &lt;p:outputLabel id="olNovoTipoPublico" for="somNovoTipoPublico" value="Tipo de público:"/&gt;
                              &lt;p:selectOneMenu id="somNovoTipoPublico" 
                                               value="#{publicoBean.tipoPublicoSelecionado}" 
                                               effect="fade" 
                                               converter="#{publicoBean.conversor}" 
                                               required="true" 
                                               requiredMessage="Selecione um tipo de público."
                                               &gt; 
                                  &lt;f:selectItem itemLabel="Selecione um item..." itemValue=""/&gt;
                                  &lt;f:selectItems value="#{publicoBean.lstMenuTipoPublico}" var="atual" itemLabel="#{atual.label}" itemValue="#{atual}"&gt;&lt;/f:selectItems&gt;
                              &lt;/p:selectOneMenu&gt;
                              &lt;p:commandButton value="Cancelar" immediate="true" onclick="dlgNovo.hide()"/&gt;
                              &lt;p:commandButton id="cbNovoSalvar" value="Salvar" 
                                               actionListener="#{publicoBean.cadastrarPublico}"
                                               oncomplete="handleSalvo(xhr, status, args);" 
                                               update=":frmPublicos:dtPublicos :frmNovo :frmPublicos:gMessages"
                                               ajax="true"/&gt;
                          &lt;/p:panelGrid&gt;
                      &lt;/p:panel&gt;
                  &lt;/h:form&gt;
              &lt;/p:dialog&gt;
  
              &lt;!-- Caixa de diálogo de exclusão --&gt;
              &lt;p:confirmDialog id="dialogoExcluir" message="Deseja realmente excluir?"
                               header="Excluir público" severity="alert" 
                               widgetVar="dlgExcluir"&gt;
                  &lt;h:form id="frmExcluir"&gt;
                      &lt;p:commandButton id="cbExcluirCancelar" value="Cancelar" onclick="dlgExcluir.hide()" type="button" /&gt; 
                      &lt;p:commandButton id="cbExcluirContinuar" value="Continuar"
                                       update=":frmPublicos:dtPublicos :frmPublicos:gMessages" 
                                       oncomplete="dlgExcluir.hide()"
                                       actionListener="#{publicoBean.excluirPublico}"/&gt;
                  &lt;/h:form&gt;
              &lt;/p:confirmDialog&gt;
              &lt;!-- Caixa de diálogo de edição --&gt;
              &lt;p:dialog id="dialogoEditar" widgetVar="dlgEditar" header="Editar público"
                        resizable="false" modal="true"&gt;
                  &lt;h:form id="frmEditar"&gt;
                      &lt;p:panel id="pEditarPublico"&gt;
                          &lt;p:messages id="mEditarMessages" redisplay="false" /&gt;
                          &lt;p:panelGrid columns="2"&gt;
                              &lt;p:outputLabel id="olEditarNomePublico" value="Nome:" for="itEditarNomePublico"/&gt;
                              &lt;p:inputText id="itEditarNomePublico" value="#{publicoBean.publicoSelecionado.nmePublico}" required="true"
                                           requiredMessage="Digite o nome do público."/&gt;
  
                              &lt;p:outputLabel id="olEditarTipoPublico" for="somEditarTipoPublico" value="Tipo de público:"/&gt;
                              &lt;p:selectOneMenu id="somEditarTipoPublico" 
                                               value="#{publicoBean.publicoSelecionado.tdTipoPublico}" 
                                               effect="fade" 
                                               converter="#{publicoBean.conversor}" 
                                               required="true"
                                               requiredMessage="Selecione um tipo de público."
                                               &gt; 
                                  &lt;f:selectItem itemLabel="Selecione um item..." itemValue=""/&gt;
                                  &lt;f:selectItems value="#{publicoBean.lstMenuTipoPublico}" 
                                                 var="atual" 
                                                 itemLabel="#{atual.label}" 
                                                 itemValue="#{atual}"&gt;&lt;/f:selectItems&gt;
                              &lt;/p:selectOneMenu&gt;
                              &lt;p:commandButton value="Cancelar" immediate="true" onclick="dlgEditar.hide()"/&gt;
                              &lt;p:commandButton id="cbEditarSalvar" value="Salvar" 
                                               actionListener="#{publicoBean.alterarPublico}"
                                               oncomplete="dlgEditar.hide();" 
                                               update=":frmPublicos:dtPublicos :frmEditar :frmPublicos:gMessages"/&gt;
                          &lt;/p:panelGrid&gt;
                      &lt;/p:panel&gt;
                  &lt;/h:form&gt;
              &lt;/p:dialog&gt;
          &lt;/p:fieldset&gt;
      &lt;/f:view&gt;
      &lt;!-- Javascript responsável por fechar a caixa de diálogo ao cadastrar--&gt;
      &lt;script type="text/javascript"&gt;
          function handleSalvo(xhr, status, args){
              if(args.salvo){
                  dlgNovo.hide();
              }
          }
          function handleEditar(xhr, status, args){
              if(args.salvo){
                  dlgEditar.hide();
              }
          }
      &lt;/script&gt;
  &lt;/ui:define&gt;
  </code></pre>
  
  <p></p>