5 Replies Latest reply on Aug 5, 2015 4:05 AM by michpetrov

    FocusManager on PopupPanel

    flavioeasy

      Hi all,

       

      i'd like ti use server side FocusManager on a PopupPanel but it seems not work when the PopupPanel is displayed for the first time.

       

      After the first ajax submission it start to work propertly.

       

      Follows the code.

       

      Any hint would be appreciated.

       

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"

                      xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j"

                      xmlns:rich="http://richfaces.org/rich">

       

          <f:event type="preRenderView" listener="#{focusManagerBean.preRenderView}" />

          <rich:panel header="Enforcing Focus of Given Input">

              <h:form id="form">

                      <a4j:commandButton render="testFocusPopupPanelEditPanel"

                                         oncomplete="if (!ajaxRequestContainsErrors()) #{rich:component('testFocusPopupPanelEditPanel')}.show();"

                                         value="Popup" >

                      </a4j:commandButton>

              </h:form>

          </rich:panel>

          <ui:include src="/uty/testFocusPopupPanel.xhtml"/>

      </ui:composition>

       

       

      <ui:composition xmlns="http://www.w3.org/1999/xhtml"

                      xmlns:h="http://java.sun.com/jsf/html"

                      xmlns:f="http://java.sun.com/jsf/core"

                      xmlns:a4j="http://richfaces.org/a4j"

                      xmlns:ui="http://java.sun.com/jsf/facelets"

                      xmlns:es="http://java.sun.com/jsf/composite/esutils"

                      xmlns:rich="http://richfaces.org/rich">

          <h:form id="testFocusPopupPanelForm">

              <rich:popupPanel id="testFocusPopupPanelEditPanel" autosized="false" domElementAttachment="parent"

                               width="720" height="325" headerClass="panel-header-class" resizeable="true">

                  <f:facet name="header">

                      <h:outputText value="Test Focus con Popup Panel"/>

                  </f:facet>

                  <f:facet name="controls">

                      <es:esUtilClosePanel varAction="#{rich:component('testFocusPopupPanelEditPanel')}.hide();"/>

                  </f:facet>

                  <a4j:outputPanel id="testFocusPopupPanelTableMod" ajaxRendered="true">

                      <rich:panel>

                          <h:panelGrid columns="2" id="testFocusPopupPanelGrid">

                              input1: <h:inputText id="input1" />

                              input2: <h:inputText id="input2" />

                              input3: <h:inputText id="input3" />

                          </h:panelGrid>

                      </rich:panel>

                      <rich:panel>

                          <a4j:commandButton value="Ajax Request" />

                      </rich:panel>

                  </a4j:outputPanel>

              </rich:popupPanel>

          </h:form>

      </ui:composition>

        • 1. Re: FocusManager on PopupPanel
          michpetrov

          Hi,

           

          if you have a problem with the FocusManager then you need to include the code that deals with it, otherwise we can't really tell what's wrong. You didn't even say what it is that you're focusing.

          • 2. Re: FocusManager on PopupPanel
            flavioeasy

            Hi,

            thanks for your replay

            i'd like to focus on the input field id="input3".

            Here is the FocusManager bean.

            Thanks a lot

             

            package uty;

            import javax.faces.bean.ManagedBean;

            import javax.faces.bean.SessionScoped;

            import org.richfaces.application.ServiceTracker;

            import org.richfaces.focus.FocusManager;

             

            @SessionScoped

            @ManagedBean

            public class FocusManagerBean {

             

                public void preRenderView() {

                    FocusManager focusManager = ServiceTracker.getService(FocusManager.class);

                    focusManager.focus("input3");

                }

            }

            • 3. Re: FocusManager on PopupPanel
              michpetrov

              You can apply focus only to visible elements. When the response comes back the popupPanel is hidden so you cannot focus anything inside it. You have to call the focus manually after the panel is shown.

              • 4. Re: FocusManager on PopupPanel
                flavioeasy

                Hi,

                could you please post a brief example of code ?

                Thanks a lot

                • 5. Re: FocusManager on PopupPanel
                  michpetrov

                  It's just JavaScript, call focus() on the element you want to focus. If you don't know the full id you can do oncomplete="#{rich:element('input2')}.focus()"