Thursday, December 29, 2011

How-to find ADF Faces Components on a Page using javascript

Search from AdfPage.PAGE
  • Search by the component ID - use findComponentByAbsoluteId function
  • Search in component that stamps its children - use findComponentByAbsoluteLocator function
 Relative Search
  •  Use findComponent function. This function searches the component clientId which can be renderer implementation specific.
 Ensure a component exists on the client before accessing it from JavaScript. To ensure client component exists (is rendered)  set clientComponent property to true.

AdfPage.PAGE.findComponentByAbsoluteLocator example:

<af:document title="Page1" id="d1">
  <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:panelGroupLayout>
        </af:panelGroupLayout>
      </f:facet>
    </af:panelStretchLayout>


    <af:resource type="javascript">
      function f1(){
        var main = AdfPage.PAGE.findComponentByAbsoluteId('main');
         alert(main);
        if(main != null) {
          ActionEvent.queue(main, true);
        }
      }
    </af:resource>
    ...

No comments:

Post a Comment