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

javascript at ADF jspx page make the buttons unclick-able on IE 11+ Win 8

By W.ZH July 2014

 

We used to have this kind of code to insert some javascript to the ADF pages.

<f:verbatim>

      <![CDATA[<!DOCTYPE html>]]>

      <![CDATA[


//javascript code here

               

            ]]>

</f:verbatim>

But we found it may cause issue when browse from Win8 + IE 11. This piece JS running on IE 11, just make the many buttons cannot be clicked on the page.

How to solve this problem?

Use this format to insert the javascript to the bottom of the jspx page.

           <af:resource type=”javascript” > 

//javascript code here

          </af:resource>

        </af:pageTemplate>