ICEfaces
  1. ICEfaces
  2. ICE-10531

ice.applyFocus not setting focus

    Details

    • Assignee Priority:
      P1
    • Support Case References:
    • Workaround Exists:
      Yes
    • Workaround Description:
      If possible, turn off the IECfaces focus retention with the icecore:config focusManaged=false tag.

      Description

      A call to ice.applyFocus is being overridden by the ICEfaces focus retention. The call is used as follows and is trying to set focus to an input that is already in the form:

                      <ice:commandButton id="clearBtn" value="Clear"
                                         actionListener="#{testBean.clear}"
                                         onclick="ice.applyFocus('iceForm:inputOne');"/>

        Activity

        Hide
        Arran Mccullough added a comment -

        I've tested this with ICEfaces 4.x as well using the standard JSF components. The same issue is seen here where focus is lost once the update is applied.

        I also tested with the <icecore:focusManager/> tag. This didn't change the behavior when having it set for the ID of the first input field: <icecore:focusManager for="inputOne">. With the Showcase demo of this component I can see similar behavior:

        • Set focus for the A component.
        • Enter in text for the required fields.
        • Click Submit, focus is not set to the A field. Should focus be set as this is what is used in the for attribute?
        Show
        Arran Mccullough added a comment - I've tested this with ICEfaces 4.x as well using the standard JSF components. The same issue is seen here where focus is lost once the update is applied. I also tested with the <icecore:focusManager/> tag. This didn't change the behavior when having it set for the ID of the first input field: <icecore:focusManager for="inputOne">. With the Showcase demo of this component I can see similar behavior: Set focus for the A component. Enter in text for the required fields. Click Submit, focus is not set to the A field. Should focus be set as this is what is used in the for attribute?
        Hide
        Arran Mccullough added a comment -

        Attached test case that shows the issue with the Compat components. I can provide the test case for the JSF components if needed. Note: the icefaces, ace, and compat jars need to be added into the war lib directory to run.

        Steps:

        • Load welcomeICEfaces.jsf
        • Enter in some text into the first field.
        • Click the Clear button, focus should be set to the first input field.
        Show
        Arran Mccullough added a comment - Attached test case that shows the issue with the Compat components. I can provide the test case for the JSF components if needed. Note: the icefaces, ace, and compat jars need to be added into the war lib directory to run. Steps: Load welcomeICEfaces.jsf Enter in some text into the first field. Click the Clear button, focus should be set to the first input field.
        Hide
        Mircea Toma added a comment - - edited

        Now that I got the test case the solution is obvious. The function that needs to be used in onclick callback should be ice.setFocus instead of ice.applyFocus. This ensures that ice.focus parameter will be changed before the submit is issued (ice.applyFocus runs with a delay).

        Setting the focus this way will enable focus retention to send back

        <eval>ice.applyFocus('...')</eval>

        command to maintain focus on the element with the ID specified in ice.focus parameter. This is a strategy that many of our components and demo apps are using.

        The test code just needs to be changed like this:

                <h:form id="iceForm">
                    <icecore:focusManager for="inputOne">
                        <h:panelGrid columns="2">
                            <ice:outputText value="Input One:"/>
                            <ice:inputText id="inputOne" value="#{testBean.inputOne}"/>
                            <ice:outputText value="Input Two:"/>
                            <ice:inputText id="inputTwo" value="#{testBean.inputTwo}"/>
                            <ice:outputText value="Input Three:"/>
                            <ice:inputText id="inputThree" value="#{testBean.inputThree}"/>
                            <ice:outputText value="Input Four:"/>
                            <ice:inputText id="inputFour" value="#{testBean.inputFour}"/>
                            <ice:commandButton id="clearBtn" value="Clear"
                                               actionListener="#{testBean.clear}"
                                               onclick="ice.setFocus('inputOne');"/>
                        </h:panelGrid>
                    </icecore:focusManager>
                </h:form>
        
        Show
        Mircea Toma added a comment - - edited Now that I got the test case the solution is obvious. The function that needs to be used in onclick callback should be ice.setFocus instead of ice.applyFocus . This ensures that ice.focus parameter will be changed before the submit is issued ( ice.applyFocus runs with a delay). Setting the focus this way will enable focus retention to send back <eval>ice.applyFocus('...')</eval> command to maintain focus on the element with the ID specified in ice.focus parameter. This is a strategy that many of our components and demo apps are using. The test code just needs to be changed like this: <h:form id= "iceForm" > <icecore:focusManager for = "inputOne" > <h:panelGrid columns= "2" > <ice:outputText value= "Input One:" /> <ice:inputText id= "inputOne" value= "#{testBean.inputOne}" /> <ice:outputText value= "Input Two:" /> <ice:inputText id= "inputTwo" value= "#{testBean.inputTwo}" /> <ice:outputText value= "Input Three:" /> <ice:inputText id= "inputThree" value= "#{testBean.inputThree}" /> <ice:outputText value= "Input Four:" /> <ice:inputText id= "inputFour" value= "#{testBean.inputFour}" /> <ice:commandButton id= "clearBtn" value= "Clear" actionListener= "#{testBean.clear}" onclick= "ice.setFocus('inputOne');" /> </h:panelGrid> </icecore:focusManager> </h:form>

          People

          • Assignee:
            Mircea Toma
            Reporter:
            Arran Mccullough
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: