0 Replies Latest reply on Oct 12, 2012 8:44 AM by Kaue Grecchi

    Avoid validating <h:inputText> when navigating to another page

    Kaue Grecchi Newbie

      My project is composed of a template with a top menu and the content, under it. There are the main page, the "view test" and the "new test" pages. The top menu:

       

      <rich:toolbar height="8px">

                              <rich:menuItem  label="Main"

                                              action="/index"/>

                              <rich:dropDownMenu label="Test" >

                                  <rich:menuItem  label="New Test"

                                                  action="/test/New"

                                                  actionListener="#{testController.prepareCreate()}"/>

                                  <rich:menuItem  label="View Test"

                                                  action="/test/View"

                                                  actionListener="#{testController.prepareView()}"/>

       

      [...]

       

      When the "New Test" item is clicked, the view is navigated to the "New.xhtml" page, where the user must input a name and save the new "test". The "prepareView()" method creates a new default "Test" object instance and sets "selected" with it:

       

       

      <h:outputLabel value="New Test"/>

                      <h:panelGrid columns="2">

                          <h:outputLabel value="Name: " for="name"/>

                          <h:inputText id="name" value="#{testController.selected.name}" size="50"/>

       

      [...]

       

      My problem: when navigating to the "new test" page, the "name" field is empty because It's required to enter a name to create it. But if the user has a change of heart and decides to go back to the view or the index, using the top menu, the view displays an error of validation on the "name" field (size must be between 1 and 100).

       

      I want to skip validation when just navigating to another page, but validate the field when I'm trying to insert a new "test". What should I change in the code?