2 Replies Latest reply on Jan 7, 2008 4:41 PM by Martin Taal

    Rerender of submitted values seems to fail when validation f

    Martin Taal Newbie

      Hi,
      I have the following use-case: I want to have a cancel link/button on my page which resets the server-side bean state and rerenders the form with empty values. However, this does not seem to work when part of the data on the form is invalid (so jsf validation fails). The fields are redisplayed with the same values.
      For example I have two input text fields on the form, both required, when I leave the second field empty (which is invalid) and click the cancel link then after the reRender the content of the first field is still shown. Although I have reset the data in the backing bean.
      Here is the commandLink I use:

      <a4j:commandLink styleClass="command-link" accesskey="c"
       value="#{messages.cancel}" reRender="form" ajaxSingle="true"
       action="#{formBean.resetInstance()}" />
      

      See the complete jsf source below, the cancel link is the a4j:commandLink with the messages.cancel label.
      I have tried different things (a4j:region for example) but the form never got reset.

      Am I doing something wrong?

      Thanks for any help on this!

      gr. Martin

      
       <h:form styleClass="form" id="form" enctype="multipart/form-data">
      
       <h:panelGrid styleClass="width-max form-background">
      
       <s:div styleClass="title">
       <h:outputText value="#{messages['Language.form.titleAdd']}"
       rendered="#{formBean.insertMode}" />
       <h:outputText value="#{messages['Language.form.titleEdit']}"
       rendered="#{formBean.editMode}" />
       </s:div>
      
       <h:panelGrid styleClass="width-max" columnClasses="form-row">
       <s:decorate id="languageCodeDecoration"
       template="/templates/facelets/edit.xhtml">
       <ui:define name="label">#{messages['Language.code']}</ui:define>
       <h:inputText id="languageCode" value="#{formBean.instance.code}"
       size="#{model.getValue('Language.code', 'text.size', '25')}"
       maxlength="#{model.getValue('Language.code', 'column.length, length.max', '255')}"
       converter="#{featureFormatter.getConverter('Language.code')}"
       onfocus="this.select();"
       required="#{model.Language.code.required}">
       <a4j:support event="onblur" reRender="languageCodeDecoration"
       bypassUpdates="false" ajaxSingle="true" />
       <a4j:support event="onchange" reRender="updateButton"
       rendered="#{formBean.editMode}"
       oncomplete="dataChanged = true;"
       onsubmit="if (dataChanged) return false;"
       action="#{formBean.setDataChanged(true)}" limitToList="true"
       bypassUpdates="true" ajaxSingle="true" />
       </h:inputText>
       </s:decorate>
       <s:decorate id="languageDescriptionDecoration"
       template="/templates/facelets/edit.xhtml">
       <ui:define name="label">#{messages['Language.description']}</ui:define>
       <h:inputText id="languageDescription"
       value="#{formBean.instance.description}"
       size="#{model.getValue('Language.description', 'text.size', '25')}"
       maxlength="#{model.getValue('Language.description', 'column.length, length.max', '255')}"
       converter="#{featureFormatter.getConverter('Language.description')}"
       onfocus="this.select();"
       required="#{model.Language.description.required}">
       <a4j:support event="onblur"
       reRender="languageDescriptionDecoration" bypassUpdates="false"
       ajaxSingle="true" />
       <a4j:support event="onchange" reRender="updateButton"
       rendered="#{formBean.editMode}"
       oncomplete="dataChanged = true;"
       onsubmit="if (dataChanged) return false;"
       action="#{formBean.setDataChanged(true)}" limitToList="true"
       bypassUpdates="true" ajaxSingle="true" />
       </h:inputText>
       </s:decorate>
       <!-- Edit button bar -->
       <h:panelGroup>
       <!-- Edit button bar -->
       <h:panelGrid id="editButtonBar" styleClass="button-bar"
       columns="3"
       columnClasses="button-bar-left, button-bar-left, button-bar-right"
       rendered="#{formBean.editMode}">
       <a4j:commandButton id="updateButton" accesskey="s"
       action="#{formBean.update}" value="#{messages.save}"
       styleClass="#{formBean.dataChanged? 'command-button' : 'command-button disabled-button'}"
       reRender="dataList,form" limitToList="true"></a4j:commandButton>
       <a4j:commandLink styleClass="command-link" accesskey="c"
       value="#{messages.cancel}" reRender="form" ajaxSingle="true"
       action="#{formBean.resetInstance()}" />
       <a4j:commandLink value="#{messages.delete}"
       focus="deleteConfirmForm:deleteConfirmNo"
       styleClass="command-link" ajaxSingle="true"
       onclick="Richfaces.showModalPanel('confirmDeletePanel')"
       rendered="#{formBean.forReference == null}" />
       <h:outputText value=""
       rendered="#{formBean.forReference != null}" />
       </h:panelGrid>
       <!-- Add button bar -->
       <h:panelGrid id="addButtonBar" styleClass="button-bar"
       columns="2" columnClasses="button-bar-left, button-bar-right"
       rendered="#{formBean.insertMode}">
       <a4j:commandButton action="#{formBean.persist}"
       value="#{messages.addNew}" styleClass="command-button"
       accesskey="s" reRender="dataList,form" limitToList="true" />
       <a4j:commandLink styleClass="command-link" accesskey="c"
       value="#{messages.cancel}" reRender="form" ajaxSingle="true"
       action="#{formBean.resetInstance()}"></a4j:commandLink>
       </h:panelGrid>
       </h:panelGroup>
       </h:panelGrid>
      
       <h:messages showDetail="true" showSummary="false" globalOnly="true"
       fatalClass="message-fatal" errorClass="message-error"
       warnClass="message-warning" infoClass="message-info" />
      
       </h:panelGrid>
      
       <script>var dataChanged =
       <h:outputText value="#{formBean.dataChanged}"/>;
       </script>
      
       </h:form>