日期:2014-05-16  浏览次数:20476 次

改写JSF 分页控件使其能支持大容量数据分页以及查询分页

?上一篇对分页的分页的封装是基于struts框架。如果要利用JSF组件实现类似的功能又该如何呢。我对JSF的痴迷始于半年以前,如今有所降温。当时对已有的分页组件作了较大的修改,并使其投入应用。?

对于JSF的学习我开始是看Core Java Server Faces和OReilly的一本Java Server Faces,个人觉得入门看前者是个不错的选择,本文关于分页组件的改写就基于Core Java Server Faces的一个分页组件的例子。

原例子是讲述JSF组件编写过程的好教材,但是其实用性不强,主要是:它把所有数据一次性的读入内存再进行分页,所以不支持大容量的分页;它不支持查询结果分页。


先贴上页面部分的代码:

?

<%@ page language="java" contentType="text/html; charset=GBK"%> <%@ page import="com.inventec.cmm.QueryBean" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://corejsf.com/pager" prefix="corejsf" %> <html> <f:view> <font color="red"><h:outputText value="#{queryBean.msg}"/></font> <HEAD><TITLE >中獎用戶信息查詢</TITLE> <META http-equiv=Content-Type content="text/html; charset=gb2312"> <link rel="stylesheet" type="text/css" href="style.css"> <script language="JavaScript" src="calendar.js" Type="Text/JavaScript" charset="gb2312" ></script> <LINK href=style.css type=text/css rel=stylesheet> </HEAD> <BODY> <TABLE cellSpacing=0 cellPadding=0 align=center bgColor=#EAEFF3 border="datagrid" width=60%> <h:form id="frmQuery"> <TR align=middle > <TD bgColor=#2153aa colSpan=7 height=34> <DIV id=reg> <font color="#FFFFD1"><STRONG>中獎信息查詢</STRONG></font> </DIV></TD></TR> <TR> <Th align=middle height=12>開始時間</Th> <TD align=center><IMG height=1 src="pics/empty.gif" width=10><h:inputText id="DATE_BEGIN" value="#{queryBean.dateBegin}" onfocus="calendar()" /><IMG height=1 src="pics/empty.gif" width=10></TD> <Th align=middle height=12 > 結束時間</Th> <TD align=center><IMG height=1 src="pics/empty.gif" width=10><h:inputText id="DATE_END" value="#{queryBean.dateEnd}" onfocus="calendar()" /><IMG height=1 src="pics/empty.gif" width=10></TD> <th align=center> 得獎用戶<IMG height=1 src="pics/empty.gif" width=10> <h:selectBooleanCheckbox value="#{queryBean.onlyPrize}" readonly="true"/> <IMG height=1 src="pics/empty.gif" width=10></th> <th align=center> 辦事處 </th> <td align=center> <IMG height=1 src="pics/empty.gif" width=10> <h:selectOneMenu id="city" required="true" value="#{queryBean.org}" > <f:selectItems value="#{queryBean.items}"/> </h:selectOneMenu><IMG height=1 src="pics/empty.gif" width=10> </td> </TR> <tr> <th>PSID號碼</th> <td align=center><IMG height=1 src="pics/empty.gif" width=5><h:inputText id="PSID" value="#{queryBean.psid}" /> <IMG height=1 src="pics/empty.gif" width=10></td> <th>驗證碼</th> <td align=center><IMG height=1 src="pics/empty.gif" width=10><h:inputText id="PWD" value="#{queryBean.pwd}" /><IMG height=1 src="pics/empty.gif" width=10></td> <td></td><th>電話號碼</th> <td align=center><IMG height=1 src="pics/empty.gif" width=10><h:inputText id="TEL" value="#{queryBean.tel}" /><IMG height=1 src="pics/empty.gif" width=10></td> </tr> <TR > <TD align=middle height=35 colspan=7><h:commandButton type="submit" value="查詢" id="Submit" actionListener="#{queryBean.reset}" /> <h:commandButton type="submit" value="导出" actionListener="#{queryBean.export}" /> </TD></TR> </h:form> <tr bgcolor=#fffff> <td align=center colspan=7 bgcolor=#FFFFD1>**提示:如果需要查看2006-10-1號信息,開始時間輸入2006-10-1,結束時間輸入2006-10-2</td></tr></table><p><h:outputText /> <p> <h:form id="frmData"> <h:dataTable styleClass="datagrid" cellspacing="0" cellpadding="1" border="1" id="userList" value="#{queryBean.dataModel