在ADF web应用中可以使用JavaScript在客户端完成需要的逻辑。下面整理一些常用的操作。
1)打开对话框
-
functionopenPopup(evt){
-
varpopup=AdfPage.PAGE.findComponent("popupId");
-
<strong>popup.show();
-
</strong>}
可以使用 af:showPopupBehavior代替。
2)隐藏对话框
-
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'){
-
-
}elseif(navigator.appName!='MicrosoftInternetExplorer'){
-
-
}
-
}
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');
-
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找到特定组件的内容。
分享到:
相关推荐
ADF_Faces
ADF Faces rich client Demo .可在包括Tomcat 6.x在内的Web服务器中直接部署运行
使用JSF开发基于Ajax的富客户端组件的文档
在ADF工程中使用javascript,我也是从官网上找的一个示例,大家可以参考一下
ADF4351结合外部环路滤波器和外部参考频率使用时,可实现小数 N分频或整数 N分频锁相环 (PLL)频率合成器。
ArcGIS API 包括: ADF API;Javascript API;Flex API;Server SOAP API
ADF41513中文手册
vue diff算法总结adf
ADF4350中文资料!!免费下载!
博文链接:https://hunte.iteye.com/blog/123559
ADF4360总结,开发过程中的一点总结,希望对您有所帮助。
ADF5355与外部环路滤波器和外部参考频率一起使用时,可实现小数N分频或整数N分频锁相环(PLL)频率合成器。ADF5355具有宽带微波VCO,一个射频(RF)输出从6.8 GHz到13.6 GHz的频率,另一个频率输出在一系列分频器...
纯手工打造,略显粗糙
ADF常用知识代码总结,managed bean常见代码,一些常见控制的解决方案!
ADF框架简介 ADF业务组件 ADF模型 ADF Task Flow ADF用户界面 ADF Faces生命周期与事件处理 安全性 实践
ADF4159中文资料,ADF4159是一款具有调制、以及快速和慢速波形产生能力 的13 GHz小数N分频频率合成器,该器件使用25位固定模数, 提供次赫兹频率分辨率。
adf4351的驱动代码、中文数据手册、相关论文讲解
ADF4351配置程序,主要是C51配置ADF5351/4350