4 Replies Latest reply on Jul 23, 2007 4:08 PM by henrik.lindberg

    focus does not work in a4j:support but setting it with oncom

    henrik.lindberg

      Hi,
      setting focus="idstring" does not work in an a4j_support for an h:input in a4j version included in rich snapshot 07 17.
      Setting the focus using onconplete="document.getElementByName['idstring'].focus();" works.

      so the focus attribute seems broken.

        • 1. Re: focus does not work in a4j:support but setting it with o
          henrik.lindberg

          where is an example that works:

           <h:form id="inputURLForm">
           <h:inputText styleClass="InputField Size-Wiz"
           id="inputURL"
           tabIndex = "1"
           value="#{wiz.properties['scriptPath'].value}"
           />
           <a4j:support event="onkeyup" reRender="wizardPagePanel"
           oncomplete="document.getElementById('inputURLForm:inputURL').focus();"
           />
           </h:form>
          


          • 2. Re: focus does not work in a4j:support but setting it with o
            henrik.lindberg

            where is an example that works:

             <h:form id="inputURLForm">
             <h:inputText styleClass="InputField Size-Wiz"
             id="inputURL"
             tabIndex = "1"
             value="#{wiz.properties['scriptPath'].value}"
             />
             <a4j:support event="onkeyup" reRender="wizardPagePanel"
             oncomplete="document.getElementById('inputURLForm:inputURL').focus();"
             />
             </h:form>
            


            • 3. Re: focus does not work in a4j:support but setting it with o

              1. why you try to set the focus manually, if a4j:support has a 'focus' attribute?

              2. I guess, you try to update the input field itself (as a part of wizard) when user types something there. If so, it is impossible. Even you will be able to set input focus in the field, the position inside the field will be lost as soon as the field is removed completely from the browser DOM tree and inserted from scratch during the re-rendering.
              You need to redesign your update behavior to avoid re-render the current field.

              • 4. Re: focus does not work in a4j:support but setting it with o
                henrik.lindberg

                1. code above works fine. The value of the field is not changed in the backing code. The reason I use it is because nothing happens if I set the focus attribute. I don't know were focus is going, but it is not on the field. When I use a4j:support focus="thefield" nothing happens. (The position is actually not lost).

                I understand now what is causing the behavior - i.e. that the field is recreated because it is in a re-rendered panel.

                I was a bt surprised that the oncomplete="..." above works but not setting the focus attribute on the a4j:support element though.