3 Replies Latest reply on May 30, 2008 2:41 AM by Robert Stone

    Execute on enter

    Robert Stone Newbie

      I have a simple search form - text field and a button. I would like to have ability to execute the search when user hits "Enter" key. The following doesn't work, can someone point me in right direction?

      <h:inputText id="quickSearch" value="#{deviceMasterFormBean.criteria.quickSearch}">
       <a4j:support event="onSubmit" actionListener="#{deviceMasterFormBean.search}" reRender="searchResultPanel,searchTogglePanel,toggleTwo">
       <a4j:actionparam value="0" assignTo="#{deviceMasterFormBean.searchType}" />
       </a4j:support>
      </h:inputText>
      <a4j:commandButton id="searchDeviceButton" value="Search" event="oncomplete"
      actionListener="#{deviceMasterFormBean.search}" reRender="searchResultPanel,searchTogglePanel,toggleTwo">
       <a4j:actionparam value="0" assignTo="#{deviceMasterFormBean.searchType}" />
      </a4j:commandButton>
      


        • 1. Re: Execute on enter
          Daniel Young Novice

          Seam provides an s:defaultAction tag which might do what you want. I took at quick look at the source in org.jboss.seam.ui.renderkit.DefaultActionRendererBase and it traps keycode 13 (enter) and clicks the given button.

          • 2. Re: Execute on enter
            Robert Stone Newbie

            Unfortunately we are not using seam on this project. It is rather strange that such major piece of functionality is not implemented by default

            • 3. Re: Execute on enter
              Robert Stone Newbie

              If anyone is interested I found the solution on this very forum. Here it is

              <h:inputText id="quickSearch" value="#{deviceMasterFormBean.criteria.quickSearch}">
               <a4j:support event="onkeyup" onsubmit="if (event.keyCode != 13) { return false}" actionListener="#{deviceMasterFormBean.search}" reRender="searchResultPanel,searchTogglePanel,toggleTwo">
               <a4j:actionparam value="0" assignTo="#{deviceMasterFormBean.searchType}" />
               </a4j:support>
              </h:inputText>


              As you can see - this does the trick:
              <a4j:support event="onkeyup" onsubmit="if (event.keyCode != 13) { return false}" />