3 Replies Latest reply on Sep 23, 2008 3:57 PM by Jens Weintraut

    Ignore form field validation

    ... ... Newbie

      I have a scenario where a user can click a New button, and a panel (initially not rendered) is marked to be rendered.

      This rendered panel has a bunch of fields (marked as required fields), and a New and Cancel button. The cancel method basically calls a backing bean method to set a showNewPanel field to false, in turn hiding the panel. However, when I try clicking Cancel with some of these fields remaining empty, form validation kicks in and wont hide the panel. If all the fields are populated, then it works a treat.

      My question, is there a way to overcome this, like temporarily ignoring form validation?


        • 1. Re: Ignore form field validation
          Daniel Young Novice

          Yes, you can use the immediate=true attribute on your button.  I'd recommend reading up on the JSF lifecycle so you understand this, but it basically means the invoke action phase is processed immediately, and the process validations and update model phases are skipped.

          • 2. Re: Ignore form field validation
            ... ... Newbie

            Perfect, thanks.

            • 3. Re: Ignore form field validation
              Jens Weintraut Apprentice

              It seems that I'm the only one having trouble implementing this with RichFaces.

              I've a form like this:

              <h:form id="browser">
                  <h:panelGrid cellpadding="5" cellspacing="0" columns="2">
                      <h:outputText value="#{msgs.name_lbl}:" />
                      <h:inputText value="#{browser.name}" />
                      <h:outputText value="#{msgs.version_lbl}:" />
                      <h:inputText value="#{browser.version}" />
                      <h:outputText value="#{msgs.description_lbl}:" />
                      <h:inputTextarea value="#{browser.descr}" rows="5" cols="50" />
                      <a4j:commandButton value="Save" action="#{adminBrowser.save}" reRender="browser, browsers" />
                      <h:commandButton value="Cancel" action="#{adminBrowser.cancel}" immediate="true" type="reset" />
                      <h:form id="browsers">
                  <f:facet name="header">
                      <h:outputText value="Name"/>
                  <h:outputText value="#{iterBrowser.name}" />
                  <f:facet name="header">
                      <h:outputText value="Version"/>
                  <h:outputText value="#{iterBrowser.version}" />
                  <f:facet name="header">
                      <h:outputText value="Edit"/>
                  <a4j:commandButton value="Edit" action="#{adminBrowser.edit}" reRender="browser, browsers">
                      <a4j:actionparam name="selectedBrowser" value="#{iterBrowser}" assignTo="#{adminBrowser.selectedBrowser}" />
                  <f:facet name="header">
                      <h:outputText value="Delete"/>
                  <a4j:commandButton value="Delete" action="#{adminBrowser.delete}" reRender="browser, browsers" />
                  <rich:datascroller for="table_browsers" />

              And what I want to do is quite common: show a list of entities, let the user add a new entity, let the user edit an entity, let the user delete an entity. It works fine. The only thing that doesn't work as exprected is the cancel button.
              I don't know how I could implement this simple usecase. The user clicks on Edit to be able to edit the selected item in the form above. Now he deletes all the content of a field and this field is bound to a bean property that is marked @NotNull and @Length(min=1). As soon as he clicks the Save button validation fails. If he clicks on Cancel nothing happens.

              Could someone help me with this issue, please?

              Thanks in advance