总结ADF Faces 中使用到的一些 JavaScript

来源:互联网 发布:微博好看的域名 编辑:程序博客网 时间:2024/06/06 07:17

关键字:ADF,JavaScript


在ADF web应用中可以使用JavaScript在客户端完成需要的逻辑。下面整理一些常用的操作。

1)打开对话框

function openPopup(evt){  var popup = AdfPage.PAGE.findComponent("popupId");  popup.show();}


可以使用 af:showPopupBehavior代替。


2)隐藏对话框

function aboutOkButton(event) {  var dialog = event.getSource();  var popup = dialog.findComponent("aboutPopup");  popup.hide();  event.cancel();}

3)组件的可见性

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

在af:panelSplitter中插入af:clientListener :
< af:clientListener method="setSplitterPos" type="propertyChange"/ >


6)执行 af:commandButton 操作

var component = AdfPage.PAGE.findComponentByAbsoluteId(commanButtonId);AdfActionEvent.queue(component, component.getPartialSubmit());


7)执行 goButton
function invokeGo(event){  var component = AdfPage.PAGE.findComponentByAbsoluteId("gb1");  var redirectEvent = new AdfRedirectEvent(component, component.getDestination(), true);  redirectEvent.queue(true);}

Hint :
AdfRedirectEvent 是一个内部类,需要设置goButton的clientComponent 属性为 true.


8)运行 file.exe

function RunExe(){  var commandtoRun = "C:\\file.exe";  var objShell = new ActiveXObject("Shell.Application");  objShell.ShellExecute(commandtoRun, "", "", "open", 1);}

9)在输入控件中改变字符的大小写
/// For IE only
function convertToUpperCase( _event ) {  var currText = null;  currText = String.fromCharCode(window.event.keyCode);  window.event.keyCode = currText.toUpperCase().charCodeAt(0);}

/// For Mozilla
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();  }}

10)识别浏览器
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  }}


11)获取屏幕宽度和高度
width = java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;hight= java.awt.Toolkit.getDefaultToolkit().getScreenSize().hight;

12)获取Mac地址,Ip地址和计算机名
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;    }  }}

13)调用 inputDate calender
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);}

14)键的keyCode

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();} 

16)双击打开LOV

function doubleClickLaunchLov(evt) {    evt.cancel();    var lov = evt.getSource();    AdfLaunchPopupEvent.queue(lov,true);}

17)关闭浏览器的当前窗口

function closeCurrentWindow(){    window.close();}

18)防止重复点击按钮
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找到特定组件的内容。







原创粉丝点击