一、ADF页面中嵌入javascript有两种方式:
1、页面中直接写入。举例:
2、使用外部链接js文件。例如:
二、ADF页面中对js函数的访问方式。
F00mc004.js源码如下:
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" οnclick="sayHtml()" 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" οnclick="sayHello()" />
- </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 ");
- }
-----------------------------------------------------------------
ADF 11g不再支持Onclick等JavaScript,而是采用<af:clientListener>来实现诸如删除某条记录的提示框。
[javascript]
view plain
copy
- function confirmDelete() {
- if (confirm('Are you sure you want to delete this record?'))
- return true;
- else
- return false;
- }
[xhtml]
view plain
copy
- <af:commandLink actionListener="#{bindings.removeRowWithKey.execute}"
- action="#{viewCalStatus.deleteCalStatus}" text="Delete">
- <af:clientListener method="confirmDelete" type="click"/>
- <af:setActionListener from="#{row.rowKeyStr}" to="#{requestScope.calStatusRow}"/>
- </af:commandLink>
ADF 中的<af:commandLink>和<af:commandButton>传递参数的方法
[xhtml]
view plain
copy
- <af:commandLink id= “” text= “”><f:param name= “param_name” value= “param_value”/></ af:commandLink>
评论:<af:commandLink>可以采用该方法传递参数,而<af:commandButton>不行。不过可以应用<h: commandButton >代替<af:commandButton>实现参数传递。
具体方法如下:
[xhtml]
view plain
copy
- <h:commandButton value="更新" action="#{emplBean.edit_action}" id="cb1"> <input type="hidden" name="emplId" value="${emplBean.employee.empno}"/></h:commandButton>