本人最近在研究EXT的东东,很是佩服这个开源团队啊!这个东东是今后web发展的主流方向.呵呵废话不多说了,下面说说最近学习的经验:
1.首先Ext的核心包主要有两个:ext-base.js和ext-all.js.
开发主要是以script为主,在开发过程中类似与我们熟悉的deaktop开发,里面包含了所用到的各种类包,例如:grid,panel,button等等.
使用起来非常方便,充分的展示了AJAX的优势.
2.并能和struts有很好的结合,在xml方面也是尤其的突出.
3.下面我给个简单例子:
关于分页的,是一个网上例子的改写.与struts的简单结合.
下面是demofy.jsp
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html>
<head>
<html:base />
<title>页分</title>
<link rel="stylesheet" type="text/css" href="../CSS/ext-all.css" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="../JS/ext-base.js"></script>
<script type="text/javascript" src="../JS/ext-all.js"></script>
</head>
<body>
<script>
Ext.onReady(function(){
var sm = new Ext.grid.CheckboxSelectionModel();
var cm = new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
sm,
{header:'编号',dataIndex:'id',sortable:true},
{header:'名称',dataIndex:'name',sortable:true},
{header:'性别',dataIndex:'sex',sortable:true,renderer:function(value){
if(value=='male'){
return " <span style='color:red;font-weight:bold;'>红男 </span> ";
}else{
return " <span style='color:green;font-weight:bold;'>绿女 </span>";
}
}},
{header:'描述',dataIndex:'descn',sortable:true}
]);
cm.defaultSortable = true;
var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'../test.do'}),
reader: new Ext.data.JsonReader({
totalProperty: 'totalProperty',
root: 'root'
},
[
{name: 'id',mapping:'id'},
{name: 'name',mapping:'name'},
{name:'sex',mapping:'sex'},
{name: 'descn',mapping:'descn'}
]),
remoteSort:true
});
var grid = new Ext.grid.GridPanel({
el: 'grid',
title:'Ext Grid Test',
width:450,
height:410,
trackMouseOver:false,
loadMask: {msg:'正在加载数据,请稍侯……'},
store:ds,
cm: cm,
sm:sm,
bbar: new Ext.PagingToolbar({
pageSize: 5,
store: ds,
displayInfo: true,
displayMsg: '当前显示 {0} - {1}条记录 /共 {2}条记录',
emptyMsg: "No topics to display"
})
});
grid.render();
ds.load({params:{start:0, limit:5}});
});
</script>
<div id="grid"></div>
<br>
Hello,Welcome to Here!
</body>
</html:html>
下面是action
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
String start = request.getParameter("start");
String limit = request.getParameter("limit");
int index = Integer.parseInt(start);
int pageSize = Integer.parseInt(limit);
String json = "{totalProperty:100,root:[";
String sex="";
for (int i = index; i < pageSize + index; i++) {
if(i%2==0)
{
sex="male";
}
else{
sex="female";
}
json += "{id:" + i + ",name:'" + i + "',sex:'"+sex+"',descn:'descn" + i
+ "'}";
if (i != pageSize + index - 1) {
json += ",";
}
}
json += "]}";
try {
response.getWriter().write(json);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("获取数据: "+start+"----"+limit);
return null;
}
///
注意就是在做的时候一定要把image包引用进来啊.
好了今天就说到这里,最近比较忙,过几天我们继续分享.
如果有朋友想和我一起研究的话,请联系我:
QQ群:10239526