在ADF web应用中可以使用JavaScript在客户端完成需要的逻辑。下面整理一些常用的操作。
1)打开对话框
- functionopenPopup(evt){
- varpopup=AdfPage.PAGE.findComponent("popupId");
- <strong>popup.show();
- </strong>}
可以使用 af:showPopupBehavior代替。
- functionaboutOkButton(event){
- vardialog=event.getSource();
- varpopup=dialog.findComponent("aboutPopup");
- <strong>popup.hide();</strong>
- event.cancel();
- }
3)组件的可见性
- functionshowText()
- {
- varoutput1=AdfUIComponent.findComponent("output1")
- varoutput2=AdfUIComponent.findComponent("output2")
- varinput=AdfUIComponent.findComponent("input")
- if(input.value=="")
- {
- output1.setVisible(true);
- }
- else
- {
- output2.setVisible(true)
- }
- }
4)从inputText中读取数据
- varinput1=document.<strong>getElementById('in1::content');</strong>
- varinput2=document.<strong>getElementById('in2::content');</strong>
- if(input1.value==input2.value)
- {
- alert("Equals");
- }
- else
- {
- alert("NoEquals");
- }
5)设置 Panel Splitter 的位置
- function<em>setSplitterPos</em>(event){
- varsource=event.getSource()
- source.<strong>setSplitterPosition</strong>(200);
- }
在af:panelSplitter中插入af:clientListener :
< af:clientListener method=" setSplitterPos " type=" propertyChange "/ >
6)执行 af:commandButton 操作
- varcomponent=AdfPage.PAGE.findComponentByAbsoluteId(commanButtonId);
- AdfActionEvent.queue(component,component.getPartialSubmit());
7)执行 goButton
- functioninvokeGo(event){
- varcomponent=AdfPage.PAGE.findComponentByAbsoluteId("gb1");
- varredirectEvent=new<strong>AdfRedirectEvent</strong>(component,component.getDestination(),true);
- redirectEvent.queue(true);
- }
Hint :
AdfRedirectEvent 是一个内部类,需要设置goButton的clientComponent 属性为 true.
8)运行 file.exe
- functionRunExe()
- {
- varcommandtoRun="C:\\file.exe";
- varobjShell=new<strong>ActiveXObject</strong>("Shell.Application");
- objShell.<strong>ShellExecute</strong>(commandtoRun,"","","open",1);
- }
9)在输入控件中改变字符的大小写
/// For IE only
- functionconvertToUpperCase(_event){
- varcurrText=null;
- currText=String.fromCharCode(window.event.keyCode);
- window.event.keyCode=currText.toUpperCase().charCodeAt(0);
- }
/// For Mozilla
- functionconvertToUpperCase(_event){
- var_keycode=_event.getKeyCode();
- if((_keycode>64&&_keycode<90)||(_keycode>96&&_keycode<123)){
- currText=String.fromCharCode(_event.getKeyCode());
- currText=currText.toUpperCase();
- var_textFieldField=document.getElementById(_event.getSource().getClientId());
- var_inputFields=_textFieldField.getElementsByTagName('INPUT');
- var_firstInputField=_inputFields[0];
- _firstInputField.value=String.concat(_firstInputField.value,currText);
- _event.cancel();
- }
- }
10)识别浏览器
- functioniEOrNot(myEvent){
- varcurrText=null;
- if(!myEvent)
- myEvent=window.event;
- if(navigator.appName=='MicrosoftInternetExplorer'){
- //IamIE
- }elseif(navigator.appName!='MicrosoftInternetExplorer'){
- //IamnotIE
- }
- }
11)获取屏幕宽度和高度
- width=java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;
- hight=java.awt.Toolkit.getDefaultToolkit().getScreenSize().hight;
12)获取Mac地址,Ip地址和计算机名
- functioncall(event){
- varsource=event.getSource();
- varmacAddress="";
- varipAddress="";
- varcomputerName="";
- varwmi=GetObject("winmgmts:{impersonationLevel=impersonate}");
- e=newEnumerator(wmi.InstancesOf("Win32_NetworkAdapterConfiguration"));
- for(;!e.atEnd();e.moveNext()){
- vars=e.item();
- if(s.DNSHostName!=null)
- {
- macAddress=s.MACAddress;
- ipAddress=s.IPAddress(0);
- computerName=s.DNSHostName;
- }
- }
- }
13)调用 inputDate calender
- functionopenDate(event){
- src=event.getSource();
- popup=src.findComponent(""+AdfRichUIPeer.CreateSubId(src.getClientId(),AdfDhtmlInputDatePeer._POPUP_ID));
- hints={alignId:src.getClientId(),align:AdfRichPopup.ALIGN_END_AFTER};
- popup.show(hints);
- }
14)键的keyCode
- functionkeyCode(evt){
- vark=evt.<strong>getKeyCode</strong>();
- }
Hint:AdfKeyStroke
15)给inputText设置光标
- functionsetFocus(evt){
- vart=document.getElementById('t1::content');//t1istheinputTextId
- t.<strong>focus</strong>();
- }
16)双击打开LOV
- functiondoubleClickLaunchLov(evt){
- evt.cancel();
- varlov=evt.getSource();
- <strong>AdfLaunchPopupEvent</strong>.queue(lov,true);
- }
17)关闭浏览器的当前窗口
- functioncloseCurrentWindow(){
- window.close();
- }
18)防止重复点击按钮
- functionpreventDuplicateClick(event){
- if(window.document.readyState!=null&&window.document.readyState!='complete'){
- event.cancel();
- }
- }
19)把jsp页面当做popup使用
- functionshowWindow(event){
- varcomSource=event.getSource();
- varidAndName=window.showModalDialog("xxxx/shortcutImgChoose.jsp",<strong>window</strong>,"dialogWidth=400px;dialogHeight=300px;location=no");
- AdfCustomEvent.queue(comSource,"changeIcon",
- {
- imgId:idAndName.split(",")[0],imgName:idAndName.split(",")[1]
- },
- }
补充:
1)findComponentByAbsoluteId与findComponent
最直接的区别是findComponent 的参数可以只是组件的ID,而findComponentByAbsoluteId的参数要包含root和目标组件之间的所有NamingContainers。
参考:http://download.oracle.com/docs/cd/E14571_01/apirefs.1111/e12046/oracle/adf/view/js/base/AdfPage.html#findComponentByAbsoluteId_String_
2)如果AdfPage.PAGE.findComponentByAbsoluteId(commanButtonId)中的commandButtonId无法确定或不容易确定,可以使用event.getSource()。
例如下面的showWindow方法可以加在af:table中的某个列中。
- functionshowWindow(event){
- var<strong>comSource</strong>=event.getSource();
- varidAndName=window.showModalDialog("xxxx/shortcutImgChoose.jsp",window,"dialogWidth=400px;dialogHeight=300px;location=no");
- AdfCustomEvent.queue(<strong>comSource</strong>,"changeIcon",
- {
- imgId:idAndName.split(",")[0],imgName:idAndName.split(",")[1]
- },
- true);
- }
3)对于一般的组件可以使用fireBug查找,使用inspectElement找到特定组件的内容。