关键字:ADF,JavaScript
在ADF web应用中可以使用JavaScript在客户端完成需要的逻辑。下面整理一些常用的操作。
1)打开对话框
function openPopup(evt){ var popup = AdfPage.PAGE.findComponent("popupId"); popup.show(); }
可以使用 af:showPopupBehavior代替。
function aboutOkButton(event) { var dialog = event.getSource(); var popup = dialog.findComponent("aboutPopup"); popup.hide(); event.cancel(); }
function showText() { var output1 = AdfUIComponent.findComponent("output1") var output2 = AdfUIComponent.findComponent("output2") var input = AdfUIComponent.findComponent("input") if (input.value == "") { output1.setVisible(true); } else { output2.setVisible(true) } }
4)从inputText中读取数据
var input1 = document.getElementById('in1::content'); var input2 = document.getElementById('in2::content'); if (input1.value == input2.value) { alert("Equals"); } else { alert("No Equals"); }
5)设置 Panel Splitter 的位置
function setSplitterPos(event) { var source = event.getSource() source.setSplitterPosition(200); }
6)执行 af:commandButton 操作
var component = AdfPage.PAGE.findComponentByAbsoluteId(commanButtonId); AdfActionEvent.queue(component, component.getPartialSubmit());
function invokeGo(event){ var component = AdfPage.PAGE.findComponentByAbsoluteId("gb1"); var redirectEvent = new AdfRedirectEvent(component, component.getDestination(), true); redirectEvent.queue(true); }
8)运行 file.exe
function RunExe() { var commandtoRun = "C:\\file.exe"; var objShell = new ActiveXObject("Shell.Application"); objShell.ShellExecute(commandtoRun, "", "", "open", 1); }
function convertToUpperCase( _event ) { var currText = null; currText = String.fromCharCode(window.event.keyCode); window.event.keyCode = currText.toUpperCase().charCodeAt(0); }
function convertToUpperCase( _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(); } }
function iEOrNot(myEvent) { var currText = null; if(!myEvent) myEvent = window.event; if(navigator.appName == 'Microsoft Internet Explorer') { // I am IE } else if(navigator.appName != 'Microsoft Internet Explorer') { // I am not IE } }
width = java.awt.Toolkit.getDefaultToolkit().getScreenSize().width; hight= java.awt.Toolkit.getDefaultToolkit().getScreenSize().hight;
function call(event) { var source = event.getSource(); var macAddress = ""; var ipAddress = ""; var computerName = ""; var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}"); e = new Enumerator(wmi.InstancesOf("Win32_NetworkAdapterConfiguration")); for(; !e.atEnd(); e.moveNext()) { var s = e.item(); if(s.DNSHostName!=null) { macAddress = s.MACAddress; ipAddress = s.IPAddress(0); computerName = s.DNSHostName; } } }
function openDate(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); }
function keyCode(evt) { var k=evt.getKeyCode(); }
Hint: AdfKeyStroke
15)给inputText设置光标
function setFocus(evt) { var t=document.getElementById('t1::content');// t1 is the inputText Id t.focus(); }
function doubleClickLaunchLov(evt) { evt.cancel(); var lov = evt.getSource(); AdfLaunchPopupEvent.queue(lov,true); }
17)关闭浏览器的当前窗口
function closeCurrentWindow(){ window.close(); }
function preventDuplicateClick(event) { if (window.document.readyState != null && window.document.readyState != 'complete') { event.cancel(); } }
19)把jsp页面当做popup使用
function showWindow(event) { var comSource = event.getSource(); var idAndName = window.showModalDialog("xxxx/shortcutImgChoose.jsp", window, "dialogWidth=400px;dialogHeight=300px;location=no"); AdfCustomEvent.queue(comSource, "changeIcon", { imgId : idAndName.split(",")[0], imgName : idAndName.split(",")[1] }, true); }
补充:
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中的某个列中。
function showWindow(event) { var comSource = event.getSource(); var idAndName = window.showModalDialog("xxxx/shortcutImgChoose.jsp", window, "dialogWidth=400px;dialogHeight=300px;location=no"); AdfCustomEvent.queue(comSource, "changeIcon", { imgId : idAndName.split(",")[0], imgName : idAndName.split(",")[1] }, true); }
3)对于一般的组件可以使用fireBug查找,使用inspectElement找到特定组件的内容。