AdfPage.PAGE.findComponentByAbsoluteId 返回 null

发布于 2024-12-20 19:25:34 字数 1529 浏览 2 评论 0原文

我试图在页面渲染过程进行时执行一些 JavaScript。 代码是:

    <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" clientComponent="true">
                            <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>

但是alert()显示“null”,最终下一个ActionEvent.queue没有执行。

谁能告诉我如何解决这个问题?

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" clientComponent="true">
                            <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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不弃不离 2024-12-27 19:25:34

看来您找到了解决方案。

https://forums.oracle.com/forums/thread.jspa?threadID=2319943

<?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>

Looks like you found your solution.

https://forums.oracle.com/forums/thread.jspa?threadID=2319943

<?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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文