7 编写JSP页面的HTML和JS代码,路径和文件名 /yuiapp/WebRoot/pages/datatable/datatable01.jsp
具体的内容是
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%String sysPath =basePath+"appjs/yuijs/build"; %>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>datatable_01</title>
<style type="text/css">
/*margin and padding on body element
can introduce errors in determining
element position and are not recommended;
we turn them off as a foundation for YUI
CSS treatments. */
body {
margin:0;
padding:0;
}
</style>
<link rel="stylesheet" type="text/css" href="<%=sysPath %>/fonts/fonts-min.css" />
<link rel="stylesheet" type="text/css" href="<%=sysPath %>/paginator/assets/skins/sam/paginator.css" />
<link rel="stylesheet" type="text/css" href="<%=sysPath %>/datatable/assets/skins/sam/datatable.css" />
<link rel="stylesheet" type="text/css" href="<%=sysPath %>/container/assets/skins/sam/container.css" />
<script type="text/javascript" src="<%=sysPath %>/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="<%=sysPath %>/connection/connection-min.js"></script>
<script type="text/javascript" src="<%=sysPath %>/json/json-min.js"></script>
<script type="text/javascript" src="<%=sysPath %>/element/element-min.js"></script>
<script type="text/javascript" src="<%=sysPath %>/paginator/paginator-min.js"></script>
<script type="text/javascript" src="<%=sysPath %>/datasource/datasource-min.js"></script>
<script type="text/javascript" src="<%=sysPath %>/datatable/datatable-min.js"></script>
<script type="text/javascript" src="<%=sysPath %>/dragdrop/dragdrop-min.js"></script>
<script type="text/javascript" src="<%=sysPath %>/container/container-min.js"></script>
<!--begin custom header content for this example-->
<style type="text/css">
/* custom styles for this example */
.yui-skin-sam .yui-dt-liner { white-space:nowrap; }
</style>
</head>
<body class="yui-skin-sam">
<div class="exampleIntro">
<p>datatable_01 practice</p>
</div>
<div id="dynamicdata"></div>
<script type="text/javascript">
YAHOO.namespace("datatable_01");
YAHOO.datatable_01.DynamicData = function() {
// Column definitions
var myColumnDefs = [
{key:"id"},
{key:"quantity"},
{key:"amount"},
{key:"title"}
];
//var myDataSource = new YAHOO.util.DataSource("/yuitab/do_getInstList.action?name=test&pageSize=10&");
var myDataSource = new YAHOO.util.DataSource("/yuitab/do_getBookList.action?");
myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
myDataSource.responseSchema = {
resultsList: "records",
fields: [
{key:"id"},
{key:"quantity"},
{key:"amount"},
{key:"title"}
],
metaFields: {
totalRecords: "totalRecords" // Access to value in the server response
}
};
// DataTable configuration
var myConfigs = {
initialRequest: "pageSize=10&sort=id&dir=asc&startIndex=0",//"sort=ptInsId&dir=asc&startIndex=0", // Initial request for first page of data
dynamicData: true, // Enables dynamic server-driven data
sortedBy : {key:"id", dir:YAHOO.widget.DataTable.CLASS_ASC}, // Sets UI initial sort arrow
paginator: new YAHOO.widget.Paginator(
{ rowsPerPage:10,
firstPageLinkLabel : "首页",
lastPageLinkLabel : "末页",
previousPageLinkLabel:"上页",
nextPageLinkLabel:"下页"
}) // Enables pagination
};
// DataTable instance
var myDataTable = new YAHOO.widget.DataTable("dynamicdata", myColumnDefs, myDataSource, myConfigs);
// Update totalRecords on the fly with value from server
myDataTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) {
oPayload.totalRecords = oResponse.meta.totalRecords;
return oPayload;
}
return {
ds: myDataSource,
dt: myDataTable
};
}();
</script>
</body>
</html>
8、重新部署应用,启动tomcat进行测试,具体结果见附件的截图
从tomcat打印的信息看,当点击了前台页面的未被点击过的链接时,会打印出我所设置的调试信息,当重新点击时,则不会打印信息,就说明YUI会解析所接收到的请求,如果是相同的请求,则不转到服务器端来了。打印信息如下:
2010-5-14 7:37:39 com.opensymphony.xwork2.validator.ActionValidatorManagerFactory <clinit>
信息: Detected AnnotationActionValidatorManager, initializing it...
getBookList is called....startIndex=0
getBookList is called....startIndex=10
getBookList is called....startIndex=0
上班时间到了,我要去坐公交车了。
我也刚刚学习YUI,希望有看到这篇文章的朋友有问题和我交流,我的QQ是604320137 手机号码是133 9175 8739
请注明是javaeye yui的即可。
附件我把yui和jar没有包含进来,望谅解。