How to adjust your ADF page focus or vertical position after the ADF PPR running

By W.ZH July 2014

Issue: After you use PPR in ADF Partial Page Rendering, sometime you find your page focus is changed as page is too long and PPR always put page focus to the top of the page.

Solution: You can use the javascript to adjust your page focus after the PPR. Either to change to an input field’s focus(). Or change the page window.location.hash by js. Here is an example.

 

  • 1.     Put this js methods to your jspx page.

 

  <![CDATA[

               

                    function setFocusId(id) {

                        var t=document.getElementById(id);

                        t.focus();

                       }

                    function setLocationHash(hsh) {

                        hsh=”#”+hsh;

                        //this.current.hash=hsh;

                        document.location.hash=hsh;

                    }

               

            ]]>

  • 2.     Add this two method to your manage bean

    public void changeClientInputFoucs(String tagID) {

        String clientId = “”;

        FacesContext facesContext = FacesContext.getCurrentInstance();

        ExtendedRenderKitService service =

            (ExtendedRenderKitService)Service.getRenderKitService(facesContext,

                                                                  ExtendedRenderKitService.class);

        UIComponent ip = facesContext.getViewRoot().findComponent(tagID);

        clientId = ip.getClientId(facesContext);

        service.addScript(facesContext, “setFocusId(‘” + clientId + “‘);”);

        return;

    }

 

    public void changeClientWindowHash(String tagID) {

        String clientId = “”;

        FacesContext facesContext = FacesContext.getCurrentInstance();

        ExtendedRenderKitService service =

            (ExtendedRenderKitService)Service.getRenderKitService(facesContext,

                                                                  ExtendedRenderKitService.class);

        clientId = tagID;

        service.addScript(facesContext,

                          “setLocationHash(‘” + clientId + “‘);”);

        return;

}

 

 

  • 3.     Then at your action listener method code, you can use sth like this to control your page vertical location of hash. You are done.

AdfFacesContext.getCurrentInstance().addPartialTarget(yourPPRtag);

        changeClientWindowHash(“your_ADF_or_HTML_tag_ID”);

        return;

  • 4.     Or

        AdfFacesContext.getCurrentInstance().addPartialTarget(yourPPRtagID);

        changeClientInputFoucs(“pt1:XXX-your_ADF_tag_ID “);

        return;

 

 

                Enjoy it!

 

 

Advertisements