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?
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?
Share Improve this question edited Dec 10, 2011 at 14:50 Tapas Bose asked Dec 10, 2011 at 14:43 Tapas BoseTapas Bose 29.9k78 gold badges220 silver badges338 bronze badges1 Answer
Reset to default 2Looks like you found your solution.
https://forums.oracle./forums/thread.jspa?threadID=2319943
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun./JSP/Page" version="2.1" xmlns:f="http://java.sun./jsf/core" xmlns:af="http://xmlns.oracle./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>