Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ADF Template: Javascript onload to resize a page

Stuart FlemingSep 26 2017 — edited Sep 26 2017

Jdeveloper 12.1.2

We have a show detail component that we use to collapse the menu.  However, when that happens, the rest of the page just moves up leaving a large white space, so we implemented some client and server listeners to get the size of the page with javascript, then resize the bottom of the page.  We also have this same code running onload.  Since this is so useful, I want to put the showDetail and javascript in a template, and have the code centralized.  The problem is that there is no af:document in a template.

How do I get this to run onload using a template?

JSF page Client and Server Listeners

    <af:document title="AIS Home Page" id="d1">

        <af:clientListener type="load" method="browserCheck"/>

       <af:serverListener type="readJavaScript" method="#{backingBeanScope.AISMenuBean.readJavaScriptValue}"/>

Show Detail Component

                        <af:showDetail disclosed="true" id="pt_sd1"

                                       styleClass="showDetailGoldText bgDarkBlue goldTopLine bgHeaderImg"

                                       disclosedText="Hide" undisclosedText="Show Menu" clientComponent="true"

                                       binding="#{backingBeanScope.AISMenuBean.showDetailUI}"

                                       inlineStyle="padding-right:20px;">

                            <af:clientListener method="browserCheck" type="disclosure"/>

                            <af:serverListener type="readJavaScript"

                                               method="#{backingBeanScope.AISMenuBean.readJavaScriptValue}"/>

                            /// components....

                   </af:showDetail>

This code goes in the JSF page's document metaContainer facet.

        <f:facet name="metaContainer">

            <af:resource type="javascript">

    function browserCheck(event){

        var eventData = event.getSource();

        var windowHeight = window.innerHeight;

        var windowWidth = window.innerWidth ;

        var param = {windowHeight:windowHeight, windowWidth:windowWidth};

        AdfCustomEvent.queue(eventData, "readJavaScript", param ,false);

    }

        </af:resource>

        </f:facet>

Java Code that receives the Javascript Input

    public void readJavaScriptValue(ClientEvent clientEvent) {

       // System.out.println("[Demo : readJavaScriptValue()] - Entry");

        Object whObject = clientEvent.getParameters().get("windowHeight");

        Object wwObject = clientEvent.getParameters().get("windowWidth");

  

        //System.out.println("Client return value - Height: " + whObject);

        //System.out.println("Client return value - Width: " + wwObject);

  

        java.lang.Double whDbl = (Double) whObject;

        int whInt = whDbl.intValue();

  

        java.lang.Double wwDbl = (Double) wwObject;

        int wwInt = wwDbl.intValue();

  

         setScreenSize(whInt  ,  wwInt ) ;

    }

    public void setScreenSize( int whInt , int wwInt  ){

        //ex:  height: calc(100vh - 130px);

        boolean isOpen = showDetailUI.isDisclosed();

        int NoticesTopFacetHeight = 500 ;

    

       // System.out.println("isOpen: " + isOpen);

        int intHeight = 0;

  

        int HeightOfHeaderOpen = 138 ;

  

        if ( wwInt < 800 ) {

          HeightOfHeaderOpen = 200 ;

        }

        int HeightOfHeaderClosed = 36 ;

        //System.out.println("setScreenSize: " + whInt);

  

        if (isOpen == true) {

            intHeight = whInt - HeightOfHeaderOpen ;

        } else {

            intHeight = whInt - HeightOfHeaderClosed;

        }

        String intHeightStr = "height:" + intHeight + "px;" ;

        // the inlineFrame and retion have inlineStyle set to:  #{pageFlowScope.regionHeight}

        ErpScopeUtils.setPageFlowScope("regionHeight", intHeightStr);

  

        // set the bottomHeightPX pageflowScope

        int bottomH = intHeight - NoticesTopFacetHeight ;  //600 is the height of the notices Top facet

  

        if (bottomH <= 0 ){

            bottomH = 0 ;

        }

  

       // System.out.println("bottomH should be: " + bottomH);

        String bottomHStr = bottomH + "px" ;

        // #{pageFlowScope.bottomHeightPX}

        ErpScopeUtils.setPageFlowScope("bottomHeightPX", bottomHStr);

        iframe.setInlineStyle(intHeightStr);

        noticesRegion.setInlineStyle(intHeightStr);

       AdfFacesContext.getCurrentInstance().addPartialTarget(iframe);

       AdfFacesContext.getCurrentInstance().addPartialTarget(this.getNoticesRegion());

    }

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 24 2017
Added on Sep 26 2017
0 comments
685 views