因为ADF是JSF的扩展,在写JS代码的时候必然要调用组件对象,这里总结了三种方法:函数
(1).AdfUIComponent.findComponent(expr)server
这种方式必须是具有实例化的组件后才能调用该方法,全部在客户端展示的ADF组件对象的类均是AdfUIComponent的子类,那么全部的ADF组件实例就都具备findComponent这个实例方法了。对象
如下是调用JS文件中的dbClickTable2函数,为要调用的组建添加一个clientListener:事件
<af:commandButton text="commandButton 2" id="btn2">get
<af:clientListener method="dbClickTable2" type="action"/>io
<af:serverListener type="dbClickServer"/>function
</af:commandButton>cli
这是JS文件里的函数:扩展
function dbClickTable2 (actionEvent){List
var buttonComponent = actionEvent.getSource();
var output1 = buttonComponent.findComponent("Output1");
alert("output1 :"+output1);
}
其中经过actionEvent.getSource()活动组件对象,而后用findComponent调用组件,其中的参数为组建的ID,这样就能够使用了。
2. AdfPage.PAGE.findComponentByAbsoluteId
这种方法不须要实例化AdfUIComponent对象就能够轻松获取到页面的ADF组件对象引用。它能获取上下文的全局对象,固然获得的应该是已经实例化的ADF组件了。仍然以上面的代码为例,只是修改了JS文件中的代码:
function dbClickTable2 (actionEvent){
var output1 = AdfPage.PAGE.findComponentByAbsoluteId("Output1");
alert("output1 :"+output1);
}
其中无需使用actionEvent事件,用该种方法一步到位便可.
3.AdfPage.PAGE.findComponentByAbsoluteId(absolute expr)
该种方法相似于方法二,也是一步到位,具体的js代码为:
function dbClickTable2 (actionEvent){
var output1 = AdfPage.PAGE.findComponentByAbsoluteId ("Output1");
alert("output1 :"+output1);
}