3 Replies Latest reply on Jun 15, 2012 8:46 AM by Brendan Healey

    Why does Enter reloads RichFaces-page?

    Oliver Ried Newbie

      This is an excerpt from my RichFaces-page:

       

      <h:form prependId="false">

       

      <a4j:commandButton value="Start" event="click" render="richTab" action="#{bean.readList}"/>

       

      <rich:panel id="richTab" style="width:2500px" header="List">

      <rich:dataTable value="#{bean.getList}" var="sp">

       

      <rich:column>

        <h:inputText value="#{sp.value}" size="7">

        <a4j:ajax event="valueChange" listener="#{bean.checkMethod}" />

        </h:inputText>

      </rich:column>

       

      </rich:dataTable>

      </rich:panel>

      </h:form>

       

      When I click the Start-button, the method readList() will be invoked and the data-table was filled.

       

      The same happens, when I click into the input-text-field and press the Enter key.

       

      When the user of my page confirms an input-text-field with Enter, the method readList() will be invoked and the data-table was filled again.

       

      I don't understand this behavior. Is this really correct?

       

      With the Enter key the user can dismiss all of his inputs, because the data-table was reloaded.

       

      Is it possible to suppress the reloading of the table after pressing the Enter key?

       

      Kind regards

      Oliver

        • 1. Re: Why does Enter reloads RichFaces-page?
          Brendan Healey Master

          Hi, you can disable form submit on enter using this:

           

          <h:inputText onkeydown=”return event.keyCode!=13″ ... - any problems with this try onkeypress=

           

          You could make the enter key behave like a tab, i.e. move to next input field with this:

           

          <h:inputText onkeydown="if (event.keyCode == 13) event.keyCode = 9;"

           

          In fact you can add onkeydown/onkeypress to the <h:form> rather than every input field and so save

          yourself some typing.

           

           

          Regards,

          Brendan.

           


          • 2. Re: Why does Enter reloads RichFaces-page?
            Oliver Ried Newbie

            Hi Brendan,

             

            onkeydown=”return event.keyCode!=13″ works on both elements: <h:inputText> and <h:form>.

             

            The following does not work:

            <h:inputText onkeydown="if (event.keyCode == 13) event.keyCode = 9;"

             

            Anyway, the first solution is great and solves my problem.

             

            Thank you very much for the quick answer.

             

            Kind regards

            Oliver

            • 3. Re: Why does Enter reloads RichFaces-page?
              Brendan Healey Master

              Ok great. Just to clarify, onkeydown="if (event.keyCode == 13) event.keyCode = 9;" should change the enter into a

              tab, and move the input focus to the next input component on the page. I often set the input focus to the first input

              component on page load, then on all but the last input component change enter into a tab. But then allow the default

              behavior on the last input component on the assumption that by the time the user has got there they will have input

              all the other information.

               

              If you're partially submitting a form with ajax then instead of allowing the default behavior on the last input component

              (full form submit) then you can .click() an ajaxified commandButton/Link instead.

               

              Regards,

              Brendan.