以查看所有list,有分页功能,返回json数据为例:
public JsonView findAll() throws Exception{
int limit = Integer.parseInt(request.getParameter("limit"));
int start = Integer.parseInt(request.getParameter("start"));
int forumSubjectId = Integer.parseInt(request.getParameter("forumSubjectId"));
String cond = "forumSubjectId=?";
Object[] args = new Object[]{forumSubjectId};
long totalCount = ForumReply.count(ForumReply.class, cond, args);
List<ForumReply> forumReplies = ForumReply.findAll(ForumReply.class, cond, args, "id", limit, start);
Map<String,Object> result = new HashMap<String,Object>();
result.put("totalCount", totalCount);
result.put("forumReplies", forumReplies);
return new JsonView(result);
}
/**
* @return
* 用途:依据版块类型显示主题列表
*/
public String searchForumRepliesList(){
HttpServletRequest request = ServletActionContext.getRequest();
int limit = Integer.parseInt(request.getParameter("limit"));
int start = Integer.parseInt(request.getParameter("start"));
String forumSubjectId = request.getParameter("forumSubjectId");
int allRowSize = forumRepliesBO.getForumRepliesDAO().
searchForumRepliesList(Integer.parseInt (forumSubjectId)).size();
msgs = forumRepliesBO.getForumRepliesDAO().searchForumRepliesListPage(Integer.parseInt(forumSubjectId),start,limit);
Map map=new HashMap();
map.put("rowCount", allRowSize);
map.put("result", msgs);
json = AjaxUtil.getJSON(map);
return "success";
}
所返回的都是json数据,可以被grid直接显示出来
var buildGrid = function(){
ds = new Ext.data.Store({
proxy:new Ext.data.HttpProxy({url:'ext_forumSubjectsAction!searchForumSubjectsList.action'}),
reader:new Ext.data.JsonReader({
totalProperty:'rowCount',
root:'result',
id:'id'
},[
'id','title','user','replyCount','readCount','lastUser','lastPostTime','lastPostTimeName'
]),
baseParams:{
limit:2,
forumBoardId:forumBoardId
}
});
ds.load({
params:{start:0}
});
grid = new Ext.grid.GridPanel({
store:ds,
columns:[
new Ext.grid.RowNumberer(),
{header:'主题',width:400,dataIndex:'title',
renderer:function(value,metadata,record){
var id = record.data.id;
var s = '<a href="javascript:showReplies('+id+')">'+value+'</a>';
return s;
}
},
{header:'回复',width:80,dataIndex:'replyCount',align:'center'},
{header:'作者',width:120,dataIndex:'user',align:'center',
renderer:function(v){
if (v){
return v['userName'];
}
}
},
{header:'阅读',width:80,dataIndex:'readCount',align:'center'},
{header:'最新文章',width:120,align:'center',
renderer:function(value,metadata,record){
var s = record.data.lastPostTimeName ;
if (record.data.lastUser){
s += '<br/>'+record.data.lastUser['userName'];
}
return s;
}
}
],
renderTo:'grid',
border:false,
viewConfig:{
forceFit:true
},
bbar:new Ext.PagingToolbar({
pageSize:2,
store:ds,
displayInfo:true
})
});
};