9 Replies Latest reply: Dec 10, 2011 10:35 AM by Tapas Bose RSS

    AdfPage.PAGE.findComponentByAbsoluteId returns null

    Tapas Bose
      Hello,
      I am trying to execute some javascript when the page rendering process is going.
      The code is:

      <af:document title="Page1" id="d1">
      <af:resource type="javascript" source="/resources/js/jquery-1.3.2.js"/>
      <af:form id="f1">
      <af:panelStretchLayout id="psl1">
      <f:facet name="center">
      <af:panelGroupLayout id="pgl1">
      <af:panelGroupLayout id="main" styleClass="AFStretchWidth" layout="vertical">
      <af:clientListener method="onMainClick" type="click"/>
                          <af:serverListener type="clickOnMain" method="#{bean.someMethod}"/>
      </af:panelGroupLayout>
      </af:panelGroupLayout>
      </f:facet>
      </af:panelStretchLayout>

      <af:resource type="javascript">
                     var main = AdfPage.PAGE.findComponentByAbsoluteId('main');
                     alert(main);
                     if(main != null) {
                          ActionEvent.queue(main, true);
                     }
      </af:resource>
                <af:resource type="javascript">
                     onMainClick = function (event) {
                          AdfCustomEvent.queue(event.getSource(), "clickOnMain", {}, true);
                     }
      </af:resource>
      </af:form>
      </af:document>

      But the alert() is showing "null" and eventually the next ActionEvent.queue is not executing.

      Can anyone tell me how can I solve this problem?
        • 1. Re: AdfPage.PAGE.findComponentByAbsoluteId returns null
          Puthanampatti
          set clientComponent="true" for that pgl
          • 2. Re: AdfPage.PAGE.findComponentByAbsoluteId returns null
            Tapas Bose
            Thanks Puthanampatti.
            I set :
            <af:panelGroupLayout id="main" styleClass="AFStretchWidth" layout="vertical" clientComponent="true">
            <af:clientListener method="onMainClick" type="click"/>
                                <af:serverListener type="clickOnMain" method="#{bean.someMethod}"/>
            </af:panelGroupLayout>

            But still the alert is null :(
            • 3. Re: AdfPage.PAGE.findComponentByAbsoluteId returns null
              Puthanampatti
              try this one...
              function f1(event) {
              var source = event.getSource();
              var comp = source.findComponent("main");
              alert(comp);
              }
              • 4. Re: AdfPage.PAGE.findComponentByAbsoluteId returns null
                Tapas Bose
                Thanks Puthanampatti.
                When and how should call the function f1()? As I am trying to execute the javascript within af:resource when the page is rendering? Don't I have to attach that f1 with some event? Also it is not possible to attach f1 with the af:document onload.
                Thanks in advance.
                • 5. Re: AdfPage.PAGE.findComponentByAbsoluteId returns null
                  Puthanampatti
                  add a clientListener under af:document with type load, it will work for sure.
                  • 6. Re: AdfPage.PAGE.findComponentByAbsoluteId returns null
                    Tapas Bose
                    If I am in a pagefragment (.jsff) so the af:document is not there. So I don't want to call f1 from on load. Is this the only way? I just want to execute some js when the page is under construction and when that af:resource block is being processed. And also if I put that af:resource within a af:panelGroupLayout and re-render that pgl then it would execute that js again.
                    • 7. Re: AdfPage.PAGE.findComponentByAbsoluteId returns null
                      Puthanampatti
                      add in the main jspx page..

                      <af:document id="d1" title="test">
                      <af:resource type="javascript">
                      function onLoadEvt(){
                      alert('on load');
                      }
                      </af:resource>
                      <af:clientListener method="onLoadEvt" type="load"/>


                      if you will need to call any other method from backing bean..have a default method call activity in the TF
                      • 8. Re: AdfPage.PAGE.findComponentByAbsoluteId returns null
                        Tapas Bose
                        Thanks. Now the alert is not null, however the method of the managed bean is not executing :( as the onMainClick js function is not executing, I put an alert within that:
                        onMainClick = function (event) {
                        alert('jym');
                        AdfCustomEvent.queue(event.getSource(), "clickOnMain", {}, true);
                                       }
                        • 9. Re: AdfPage.PAGE.findComponentByAbsoluteId returns null
                          Tapas Bose
                          Here is the solution:

                          <?xml version='1.0' encoding='UTF-8'?>
                          <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
                          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
                          <jsp:directive.page contentType="text/html;charset=UTF-8"/>
                          <f:view>
                          <af:document title="Page1" id="d1" clientComponent="true">
                          <af:resource type="javascript" source="/resources/js/jquery-1.3.2.js"/>
                          <af:form id="f1">
                          <af:panelStretchLayout id="psl1">
                          <f:facet name="center">
                          <af:panelGroupLayout id="pgl1">
                          <af:panelGroupLayout id="main" styleClass="AFStretchWidth" layout="vertical" clientComponent="true">
                          <af:clientListener method="onMainClick" type="click"/>
                                              <af:serverListener type="clickOnMain" method="#{college.onLoad}"/>
                          </af:panelGroupLayout>
                          </af:panelGroupLayout>
                          </f:facet>
                          </af:panelStretchLayout>           
                          </af:form>
                          <af:resource type="javascript">               
                          onBodyLoad = function (event) {                 
                          fireEvent(document.getElementById(AdfPage.PAGE.findComponentByAbsoluteId('main').getClientId()), 'click');
                          }

                          fireEvent = function (element, eventType){
                          if (element.fireEvent) {
                          element.fireEvent('on' + eventType);
                          } else {
                          var eventObj = document.createEvent('Events');
                          eventObj.initEvent(eventType, true, false);
                          element.dispatchEvent(eventObj);
                          }
                          }

                          onMainClick = function (event) {                           
                          AdfCustomEvent.queue(event.getSource(), "clickOnMain", {}, true);
                          }
                          </af:resource>
                          <af:clientListener method="onBodyLoad" type="load"/>
                          </af:document>
                          </f:view>
                          </jsp:root>