5 Replies Latest reply on Sep 3, 2009 4:39 AM by ilya_shaikovsky

    Setting focus to an element which is rerendered

    orik

      I'm trying to set the focus to an element which is in the rerendered section with no luck.

      <a4j:region>
      <h:panelGroup id="section">
       <h:inputText id="input" value="#{bean.someValue}" />
       <h:inputText id="trigger" value="#{bean.trigger}">
       <a4j:support event="onblur" reRender="section" focus="input" />
       </h:inputText>
      </h:panelGroup>
      </a4j:region>
      


      In the log I can see it's trying to set the focus to the correct element, and actually says it did, but upon completion the focus is not set.

      Ideas?

        • 1. Re: Setting focus to an element which is rerendered
          ilya_shaikovsky

          RF version?

          • 2. Re: Setting focus to an element which is rerendered
            orik

            Using 3.3.1 GA.

            • 3. Re: Setting focus to an element which is rerendered
              ilya_shaikovsky

              works ok for me at 3.3.2 snapshot. try 3.3.2 CR1.

              • 4. Re: Setting focus to an element which is rerendered
                orik

                With h:inputText it does works fine,
                I'm getting this problem when trying to set the focus to a rich:combobox, and the target combobox is located after the current element in the tree.
                If the combobox target element is before the element initiating the request there is no problem.

                In my case:

                <h:panelGrid columns="3" id="criteriaGrid" width="100%">
                 <h:panelGroup id="columnPanelGroup">
                 <rich:comboBox id="selectedColumCombobox" value="#{bean.selectedColumn}" suggestionValues="#{bean.selectedColumnsList}">
                 <a4j:support id="columnValidator" reRender="criteriaGrid" event="onblur" actionListener="#{bean.validateSelectedColumn}" focus="test"/>
                 </rich:comboBox>
                 </h:panelGroup>
                
                 <h:panelGroup id="testPanelGroup">
                 <rich:comboBox id="test" value="#{bean.selectedColumn}" suggestionValues="#{bean.selectedColumnsList}" />
                 </h:panelGroup>
                </h:panelGrid>
                


                From checking the log output i can see that the focus is set to the test element BEFORE the test element script is evaluated.

                Can it be that evaluating the script causes the element to loose focus?

                Verified this on both 3.3.1 and 3.3.2 CR1.

                Log:
                debug[12:15:14,708]: call getElementById for id= _A4J.AJAX.focus
                debug[12:15:14,709]: focus must be set to control
                ...:test
                debug[12:15:14,709]: Set focus to control

                ...

                debug[12:15:14,751]: Evaluate script replaced area in document: // new Richfaces.ComboBox("...:test",{'listOptions':{'itemsText':['Txn ID','Link Status','Action','Id','Origin Ticket ID','Master ID','Lifecycle Status','Matching Status','Approval Status','Allocation....



                • 5. Re: Setting focus to an element which is rerendered
                  ilya_shaikovsky