因爲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);
}