`
dragonxiangfu
  • 浏览: 157125 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

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

阅读更多

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

1)打开对话框

[javascript]view plaincopyprint?
  1. functionopenPopup(evt){
  2. varpopup=AdfPage.PAGE.findComponent("popupId");
  3. <strong>popup.show();
  4. </strong>}


可以使用 af:showPopupBehavior代替。


2)隐藏对话框

[javascript]view plaincopyprint?
  1. functionaboutOkButton(event){
  2. vardialog=event.getSource();
  3. varpopup=dialog.findComponent("aboutPopup");
  4. <strong>popup.hide();</strong>
  5. event.cancel();
  6. }

3)组件的可见性

[javascript]view plaincopyprint?
  1. functionshowText()
  2. {
  3. varoutput1=AdfUIComponent.findComponent("output1")
  4. varoutput2=AdfUIComponent.findComponent("output2")
  5. varinput=AdfUIComponent.findComponent("input")
  6. if(input.value=="")
  7. {
  8. output1.setVisible(true);
  9. }
  10. else
  11. {
  12. output2.setVisible(true)
  13. }
  14. }

4)从inputText中读取数据

[javascript]view plaincopyprint?
  1. varinput1=document.<strong>getElementById('in1::content');</strong>
  2. varinput2=document.<strong>getElementById('in2::content');</strong>
  3. if(input1.value==input2.value)
  4. {
  5. alert("Equals");
  6. }
  7. else
  8. {
  9. alert("NoEquals");
  10. }

5)设置 Panel Splitter 的位置

[javascript]view plaincopyprint?
  1. function<em>setSplitterPos</em>(event){
  2. varsource=event.getSource()
  3. source.<strong>setSplitterPosition</strong>(200);
  4. }

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


6)执行 af:commandButton 操作

[javascript]view plaincopyprint?
  1. varcomponent=AdfPage.PAGE.findComponentByAbsoluteId(commanButtonId);
  2. AdfActionEvent.queue(component,component.getPartialSubmit());


7)执行 goButton
[javascript]view plaincopyprint?
  1. functioninvokeGo(event){
  2. varcomponent=AdfPage.PAGE.findComponentByAbsoluteId("gb1");
  3. varredirectEvent=new<strong>AdfRedirectEvent</strong>(component,component.getDestination(),true);
  4. redirectEvent.queue(true);
  5. }

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


8)运行 file.exe

[javascript]view plaincopyprint?
  1. functionRunExe()
  2. {
  3. varcommandtoRun="C:\\file.exe";
  4. varobjShell=new<strong>ActiveXObject</strong>("Shell.Application");
  5. objShell.<strong>ShellExecute</strong>(commandtoRun,"","","open",1);
  6. }

9)在输入控件中改变字符的大小写
/// For IE only
[javascript]view plaincopyprint?
  1. functionconvertToUpperCase(_event){
  2. varcurrText=null;
  3. currText=String.fromCharCode(window.event.keyCode);
  4. window.event.keyCode=currText.toUpperCase().charCodeAt(0);
  5. }

/// For Mozilla
[javascript]view plaincopyprint?
  1. functionconvertToUpperCase(_event){
  2. var_keycode=_event.getKeyCode();
  3. if((_keycode>64&&_keycode<90)||(_keycode>96&&_keycode<123)){
  4. currText=String.fromCharCode(_event.getKeyCode());
  5. currText=currText.toUpperCase();
  6. var_textFieldField=document.getElementById(_event.getSource().getClientId());
  7. var_inputFields=_textFieldField.getElementsByTagName('INPUT');
  8. var_firstInputField=_inputFields[0];
  9. _firstInputField.value=String.concat(_firstInputField.value,currText);
  10. _event.cancel();
  11. }
  12. }

10)识别浏览器
[javascript]view plaincopyprint?
  1. functioniEOrNot(myEvent){
  2. varcurrText=null;
  3. if(!myEvent)
  4. myEvent=window.event;
  5. if(navigator.appName=='MicrosoftInternetExplorer'){
  6. //IamIE
  7. }elseif(navigator.appName!='MicrosoftInternetExplorer'){
  8. //IamnotIE
  9. }
  10. }


11)获取屏幕宽度和高度
[javascript]view plaincopyprint?
  1. width=java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;
  2. hight=java.awt.Toolkit.getDefaultToolkit().getScreenSize().hight;

12)获取Mac地址,Ip地址和计算机名
[javascript]view plaincopyprint?
  1. functioncall(event){
  2. varsource=event.getSource();
  3. varmacAddress="";
  4. varipAddress="";
  5. varcomputerName="";
  6. varwmi=GetObject("winmgmts:{impersonationLevel=impersonate}");
  7. e=newEnumerator(wmi.InstancesOf("Win32_NetworkAdapterConfiguration"));
  8. for(;!e.atEnd();e.moveNext()){
  9. vars=e.item();
  10. if(s.DNSHostName!=null)
  11. {
  12. macAddress=s.MACAddress;
  13. ipAddress=s.IPAddress(0);
  14. computerName=s.DNSHostName;
  15. }
  16. }
  17. }

13)调用 inputDate calender
[javascript]view plaincopyprint?
  1. functionopenDate(event){
  2. src=event.getSource();
  3. popup=src.findComponent(""+AdfRichUIPeer.CreateSubId(src.getClientId(),AdfDhtmlInputDatePeer._POPUP_ID));
  4. hints={alignId:src.getClientId(),align:AdfRichPopup.ALIGN_END_AFTER};
  5. popup.show(hints);
  6. }

14)键的keyCode

[javascript]view plaincopyprint?
  1. functionkeyCode(evt){
  2. vark=evt.<strong>getKeyCode</strong>();
  3. }

Hint:AdfKeyStroke

15)给inputText设置光标

[javascript]view plaincopyprint?
  1. functionsetFocus(evt){
  2. vart=document.getElementById('t1::content');//t1istheinputTextId
  3. t.<strong>focus</strong>();
  4. }

16)双击打开LOV

[javascript]view plaincopyprint?
  1. functiondoubleClickLaunchLov(evt){
  2. evt.cancel();
  3. varlov=evt.getSource();
  4. <strong>AdfLaunchPopupEvent</strong>.queue(lov,true);
  5. }

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

[javascript]view plaincopyprint?
  1. functioncloseCurrentWindow(){
  2. window.close();
  3. }

18)防止重复点击按钮
[javascript]view plaincopyprint?
  1. functionpreventDuplicateClick(event){
  2. if(window.document.readyState!=null&&window.document.readyState!='complete'){
  3. event.cancel();
  4. }
  5. }


19)把jsp页面当做popup使用

[javascript]view plaincopyprint?
  1. functionshowWindow(event){
  2. varcomSource=event.getSource();
  3. varidAndName=window.showModalDialog("xxxx/shortcutImgChoose.jsp",<strong>window</strong>,"dialogWidth=400px;dialogHeight=300px;location=no");
  4. AdfCustomEvent.queue(comSource,"changeIcon",
  5. {
  6. imgId:idAndName.split(",")[0],imgName:idAndName.split(",")[1]
  7. },
  8. }


补充:

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中的某个列中。

[javascript]view plaincopyprint?
  1. functionshowWindow(event){
  2. var<strong>comSource</strong>=event.getSource();
  3. varidAndName=window.showModalDialog("xxxx/shortcutImgChoose.jsp",window,"dialogWidth=400px;dialogHeight=300px;location=no");
  4. AdfCustomEvent.queue(<strong>comSource</strong>,"changeIcon",
  5. {
  6. imgId:idAndName.split(",")[0],imgName:idAndName.split(",")[1]
  7. },
  8. true);
  9. }


3)对于一般的组件可以使用fireBug查找,使用inspectElement找到特定组件的内容。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics