论坛首页 Java企业应用论坛

hibernate+dwr+js+html 分页(3)

浏览 2730 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-10-20  
7、PageUtil类
package com.linbs.usermanage.page;

import com.linbs.usermanage.model.User;
import com.linbs.usermanage.service.UserService;
import com.linbs.usermanage.service.impl.UserServiceImpl;

public class PageUtil {
	private static UserService userService = new UserServiceImpl();

	public static Page getPage(int totalRows, int currentPage, String pagerMethod,int pageSize) {
		Page page = new Page(totalRows,pageSize);
		page.refresh(currentPage);
		if (pagerMethod != null) {
			if (pagerMethod.equals("first")) {
				page.first();
			} else if (pagerMethod.equals("previous")) {
				page.previous();
			} else if (pagerMethod.equals("next")) {
				page.next();
			} else if (pagerMethod.equals("last")) {
				page.last();
			}
		}
		return page;
	}
}

8、dwr层接口
package com.linbs.usermanage.controller.dwr;

import java.util.HashSet;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.linbs.core.common.exception.BusinessException;
import com.linbs.usermanage.model.Module;
import com.linbs.usermanage.model.Placard;
import com.linbs.usermanage.page.Page;
import com.linbs.usermanage.service.ModuleService;
import com.linbs.usermanage.service.PlacardService;
import com.linbs.usermanage.service.impl.ModuleServiceImpl;
import com.linbs.usermanage.service.impl.PlacardServiceImpl;

public class PlacardManager {

public List<Placard> getPlacardByPage(int startIndex , int length, Placard placardExample, int moduleId){
		if(moduleId!=0){
			placardExample.setModules(new HashSet(0));
			Module module = new Module();
			module.setId(moduleId);
			placardExample.getModules().add(module);
		}
		return placardService.getPlacardByPage(startIndex, length, placardExample);
	}
	
	public Page getPage(Placard placardExample, int moduleId, int currentPage,int pageSize,String pagerMethod){
		if(moduleId!=0){
			placardExample.setModules(new HashSet(0));
			Module module = new Module();
			module.setId(moduleId);
			placardExample.getModules().add(module);
		}
		int totalRows = placardService.getPlacardLength(placardExample);
		Page page = PageUtil.getPage(totalRows, currentPage,pagerMethod,pageSize);
                return page;
	}
}

9、视图层调用 js:
var cellFuncs = [
		function(data) {
			var str = "<input type=\"checkbox\" name=\"chooseRow\" value=\""+data.id+"\">";
			return str
		}, 
		function(data) {
			return "<a href=\"placardShow.html?placardId="+data.id+"\" target=new>"+data.title;
		}, 
		function(data) {
			return data.publisher;
		}, 
		function(data) {
			var submitTime = data.submitTime;
			if(submitTime!=null)return submitTime.toLocaleDateString();
			else return "";
		}, 
		function(data) {
			var moduleValues = "";
			for (var i = 0; i < data.modules.length; i++) {
				moduleValues = moduleValues + data.modules[i].moduleName;
				if (i != (data.modules.length - 1))
					moduleValues += ";";
			}
			return moduleValues;
		},
		function(data) {
			var oprations = "";
			if(data.status==0) 
			 oprations += "<a href=\"#\" onclick=\"changePlacardStatus(true,'"+data.id+"')\">设为最新</a>&nbsp;&nbsp;";
			else oprations += "<a href=\"#\" onclick=\"changePlacardStatus(false,'"+data.id+"')\">取消最新</a>&nbsp;&nbsp;";
			oprations += "<a href=\"#\" onclick=\"showUpdatePlacardLayer('"+data.id+"')\">修改</a>&nbsp;&nbsp;";
			oprations += "<a href=\"#\" onclick=\"deleteOnePlacard('"+data.id+"')\">删除</a>";
			return oprations
		}
];

var page;
var placardSample;
var moduleSample;
var pageSize =15;
function getPlacardInfo(placard,moduleId,currentPage,pagerMethod) {
	placardSample = placard;
	moduleSample = moduleId;
//取得页面Page
PlacardManager.getPage(placard,moduleId,currentPage,pageSize,pagerMethod,function(data){
		page = data;
		setPageMenu(page, $('pageMenu'));
//根据Page取得当前页面公告
PlacardManager.getPlacardByPage(page.startIndex,page.pageSize,placardSample,moduleSample,function(result){
			showPlacardInfo(result);
		});		
	});
}
//显示公告信息
function showPlacardInfo(data){
	dwr.util.removeAllRows("placardInfo");
	dwr.util.addRows("placardInfo", data, cellFuncs, {
				cellCreator : function(options) {
					var td = document.createElement("td");
					td.align = 'center';
					return td;
				},
				escapeHtml : false
	});
}

/**
 * 分页标签
 * @param {} page
 * @param {} pageMenu
 */
function setPageMenu(page, pageMenu) {
	var menuInfo = "";
	menuInfo += "共" + page.totalRows + "条记录" + " 共" + page.totalPage + "页 当前第"
			+ page.currentPage + "页";
	menuInfo += " <a href=\"#\" onclick=\"getPlacardInfo(placardSample,moduleSample," + page.currentPage
			+",'first')\">首页</a>";
	if (page.hasPrePage) {
		menuInfo += " <a href=\"#\" onclick=\"getPlacardInfo(placardSample,moduleSample," + page.currentPage
			+",'previous')\">上一页</a>";
	}
	if (page.hasNextPage) {
		menuInfo += " <a href=\"#\" onclick=\"getPlacardInfo(placardSample,moduleSample," + page.currentPage
			+",'next')\">下一页</a>";
	}
	menuInfo += " <a href=\"#\" onclick=\"getPlacardInfo(placardSample,moduleSample," + page.currentPage
			+",'last')\">末页</a>";
	pageMenu.innerHTML = menuInfo;
}
/**
 * 查询公告
 */
function queryPlacard(){
	var title = $('titleSample').value;
	var publisher = $('publisherSample').value;
	var module = $('modulesInfo').value;
	var placard={modules:[]};
	if(!isNull(title)) placard.title = title;
	if(!isNull(publisher)) placard.publisher = publisher;
	getPlacardInfo(placard,module,1,pageSize,"");
}

10、页面jsp:
<table width=99%
						style="margin-top: 5px; margin-bottom: 5px; margin-left: 5px; margin-right: 5px;">
						<tr>
							<td>
								标题:
								<input type="text" id="titleSample">
							<br></td>
							<td>
								发布人:
								<input type="text" id="publisherSample">
							<br></td>
							<td>
								所属模块:
								<select id="modulesInfo">
									<option value="0">
										--所有--
									</option>
								</select>
							<br></td>
							<td>
								<input type="button" value="查询" onclick="queryPlacard();">
							<br></td>
						</tr>
					</table>
					<table width=99% style="margin-top:5px;margin-bottom:5px;margin-left:5px;margin-right:5px;">
						<thead>
							<tr>
								<th>&nbsp;<br></th>
								<th>标题<br></th>
								<th>发布人<br></th>
								<th>修改时间<br></th>
								<th>所属模块<br></th>
								<th>&nbsp;<br></th>
							</tr>
						</thead>
						<tbody id="placardInfo">
						</tbody>
						<tfoot>
							<tr>
								<td colspan="6" align="right">
									<div id="pageMenu"></div>
								</td>
							</tr>
						</tfoot>
					</table>
					<table width=99% style="margin-top:5px;margin-bottom:5px;margin-left:5px;margin-right:5px;">
						<tr>
							<td><input type="checkbox" id="isChooseAll" onclick="chooseAll();">全选
								 &nbsp;
								<input type="button" value="删除选中公告" onclick="deletePlacards();">
								&nbsp;
								<input type="button" value="将选中公告设为最新" onclick="changePlacardsStatus();">
							<br></td>
						</tr>
					</table>	
   发表时间:2008-10-21  
.... 能不能发个工程出来啊。
0 请登录后投票
   发表时间:2008-10-21  
zcjava 写道
.... 能不能发个工程出来啊。

同问!

整个项目发出来可看的更清楚!

感谢LZ辛勤劳动
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics