六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 26|回复: 0

ADF页面使用javascript示例

[复制链接]

升级  3.33%

11

主题

11

主题

11

主题

秀才

Rank: 2

积分
55
 楼主| 发表于 2013-2-7 17:16:42 | 显示全部楼层 |阅读模式
一、ADF页面中嵌入javascript有两种方式:

1、页面中直接写入。举例:
      <af:resource type="javascript">        function sayHello() {            alert("Hello, world!")        }                function sayJianlong() {            alert("Hello, world!")            var greeting = AdfPage.PAGE.findComponentByAbsoluteId("greeting");            alert(greeting);            greeting.setValue("http://www.ejianlong.com");        }                function sayHtml() {            var name = document.getElementById("name").value;            alert(name);        }              </af:resource>  

2、使用外部链接js文件。例如:

<af:resource type="javascript" source="/mc/js/F00mc004.js"></af:resource>

二、ADF页面中对js函数的访问方式。

<?xml version='1.0' encoding='UTF-8'?><!-- ADF中使用javascript示例 --><jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"          xmlns:f="http://java.sun.com/jsf/core"          xmlns:h="http://java.sun.com/jsf/html"          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">  <jsp:directive.page contentType="text/html;charset=UTF-8"/>  <f:view>    <af:document id="d1" title="my test for javascript\html\adf">          <!-- ADF Tag内嵌JS代码方式 -->      <af:resource type="javascript">        function sayHello() {            alert("Hello, world!")        }                function sayJianlong() {            alert("Hello, world!")            var greeting = AdfPage.PAGE.findComponentByAbsoluteId("greeting");            alert(greeting);            greeting.setValue("http://www.ejianlong.com");        }                function sayHtml() {            var name = document.getElementById("name").value;            alert(name);        }              </af:resource>            <af:resource type="javascript" source="/mc/js/F00mc004.js"></af:resource>            <!-- 测试ADF JS调用 -->      <af:commandButton text="Say Hello" id="button1">         <af:clientListener method="sayHello" type="click"/>      </af:commandButton>            <!-- 测试ADF JS调用,通过ADF js组件访问ADF Component -->      <af:commandButton text="Say Jianlong and show it's websit url" id="button12">         <af:clientListener method="sayJianlong" type="click"/>      </af:commandButton>      <af:outputText id="greeting" value="" clientComponent="true"/>            <!-- 测试ADF Tag与HTML Tag混用,并通过HTML Tag访问ad:resource标记的JS function -->      <af:panelBox text="PanelBox1" id="pb1">        <f:facet name="toolbar"/>        <form id="form1">            <input id="name" type="text" value="please input your name" />            <input id="button" type="button"  value="sysHTML" />        </form>      </af:panelBox>            <!-- 测试ADF Tag与JSF Tag混用,并通过JSF Tag访问ad:resource标记的JS function -->      <af:panelBox text="PanelBox2" id="pb2">        <f:facet name="toolbar"/>        <h:commandButton id="testJSF" type="button" value="testJSF"  />      </af:panelBox>      <af:panelFormLayout id="pfl1">        <af:form id="f1">          <af:commandButton text="access js function from js file" id="cb1">            <af:clientListener type="click" method="sayOutFileJS"/>          </af:commandButton>        </af:form>        <f:facet name="footer"/>      </af:panelFormLayout>    </af:document>  </f:view></jsp:root>

F00mc004.js源码如下:
function sayOutFileJS() {    alert("This is function which is in a js file ");}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表