⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 在jsf中实现分页(二).htm

📁 jsf分页处理, 很 好的例子, 可以很方便的移植
💻 HTM
📖 第 1 页 / 共 5 页
字号:
            <DIV>
            <DIV class="right t_number"><A class=bold 
            onclick="window.clipboardData.setData('text','http://www.agilejava.org/java/viewthread.php?tid=8&amp;page=1#pid2262')" 
            href="http://www.agilejava.org/java/viewthread.php?tid=8&amp;extra=&amp;page=1###">#1</A></DIV>
            <DIV style="PADDING-TOP: 4px">发表于 2006-1-29 18:36&nbsp; <A 
            href="http://www.agilejava.org/java/viewpro.php?uid=1">资料</A> <A 
            href="http://www.agilejava.org/space/index.php?action/space/uid/1" 
            target=_blank>个人空间</A> <A 
            href="http://www.agilejava.org/java/pm.php?action=send&amp;uid=1" 
            target=_blank>短消息</A>&nbsp; </DIV></DIV></TD></TR>
        <TR>
          <TD class=line style="PADDING-TOP: 10px" vAlign=top height="100%"><A 
            title="评分 0" 
            href="http://www.agilejava.org/java/misc.php?action=viewratings&amp;tid=8&amp;pid=2262" 
            name=pid2262></A><SPAN class=bold>在JSF中实现分页(二)</SPAN><BR><BR>
            <DIV style="FONT-SIZE: 12px">
            <P>&nbsp;&nbsp;&nbsp; 
            前面一篇直接使用了Myfaces中的两个Component完成了一个简单的分页,这里将会介绍一种On-demand 
            loading的方法来进行分页,仅仅在需要数据的时候加载。</P>
            <P>&nbsp;&nbsp;&nbsp; 
            先来说一些题外话,为了实现这种方式的分页,公司里大约5-6个人做了半个多月的工作,扩展了dataTable,修改了dataScrollor,以及各种其他的方法,但是都不是很优雅。在上个月底的时候,在Myfaces的Mail 
            List中也针对这个问题展开了一系列的讨论,最后有人总结了讨论中提出的比较好的方法,提出了以下的分页方法,也是目前实现的最为优雅的方法,也就是不对dataTable和dataScrollor做任何修改,仅仅通过扩展DataModel来实现分页。</P>
            <P>&nbsp;&nbsp;&nbsp; 
            DataModel是一个抽象类,用于封装各种类型的数据源和数据对象的访问,JSF中dataTable中绑定的数据实际上被包装成了一个DataModel,以消除各种不同数据源和数据类型的复杂性,在前面一篇中我们访问数据库并拿到了一个List,交给dataTable,这时候,JSF会将这个List包装成ListDataModel,dataTable访问数据都是通过这个DataModel进行的,而不是直接使用List。</P>
            <P>&nbsp;&nbsp;&nbsp; 
            接下来我们要将需要的页的数据封装到一个DataPage中去,这个类表示了我们需要的一页的数据,里面包含有三个元素:datasetSize,startRow,和一个用于表示具体数据的List。datasetSize表示了这个记录集的总条数,查询数据的时候,使用同样的条件取count即可,startRow表示该页的起始行在数据库中所有记录集中的位置。<BR><BR><SPAN 
            lang=EN-US><o:p></P>
            <DIV 
            style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG 
            id=Codehighlighter1_0_271_Open_Image 
            onclick="this.style.display='none'; Codehighlighter1_0_271_Open_Text.style.display='none'; Codehighlighter1_0_271_Closed_Image.style.display='inline'; Codehighlighter1_0_271_Closed_Text.style.display='inline';" 
            src="在JSF中实现分页(二).files/ExpandedBlockStart.gif" align=top><IMG 
            id=Codehighlighter1_0_271_Closed_Image style="DISPLAY: none" 
            onclick="this.style.display='none'; Codehighlighter1_0_271_Closed_Text.style.display='none'; Codehighlighter1_0_271_Open_Image.style.display='inline'; Codehighlighter1_0_271_Open_Text.style.display='inline';" 
            src="在JSF中实现分页(二).files/ContractedBlock.gif" align=top><SPAN 
            id=Codehighlighter1_0_271_Closed_Text 
            style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**&nbsp;*/</SPAN><SPAN 
            id=Codehighlighter1_0_271_Open_Text><SPAN 
            style="COLOR: #008000">/**</SPAN><SPAN 
            style="COLOR: #008000"><BR><IMG src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;*&nbsp;A&nbsp;simple&nbsp;class&nbsp;that&nbsp;represents&nbsp;a&nbsp;"page"&nbsp;of&nbsp;data&nbsp;out&nbsp;of&nbsp;a&nbsp;longer&nbsp;set,&nbsp;ie&nbsp;a<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;*&nbsp;list&nbsp;of&nbsp;objects&nbsp;together&nbsp;with&nbsp;info&nbsp;to&nbsp;indicate&nbsp;the&nbsp;starting&nbsp;row&nbsp;and&nbsp;the&nbsp;full<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;*&nbsp;size&nbsp;of&nbsp;the&nbsp;dataset.&nbsp;EJBs&nbsp;can&nbsp;return&nbsp;instances&nbsp;of&nbsp;this&nbsp;type&nbsp;when&nbsp;returning<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;*&nbsp;subsets&nbsp;of&nbsp;available&nbsp;data.<BR><IMG 
            src="在JSF中实现分页(二).files/ExpandedBlockEnd.gif" 
            align=top>&nbsp;</SPAN><SPAN 
            style="COLOR: #008000">*/</SPAN></SPAN><SPAN 
            style="COLOR: #000000"><BR><IMG src="在JSF中实现分页(二).files/None.gif" 
            align=top></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN 
            style="COLOR: #000000">&nbsp;</SPAN><SPAN 
            style="COLOR: #0000ff">class</SPAN><SPAN 
            style="COLOR: #000000">&nbsp;DataPage<BR><IMG 
            id=Codehighlighter1_295_1342_Open_Image 
            onclick="this.style.display='none'; Codehighlighter1_295_1342_Open_Text.style.display='none'; Codehighlighter1_295_1342_Closed_Image.style.display='inline'; Codehighlighter1_295_1342_Closed_Text.style.display='inline';" 
            src="在JSF中实现分页(二).files/ExpandedBlockStart.gif" align=top><IMG 
            id=Codehighlighter1_295_1342_Closed_Image style="DISPLAY: none" 
            onclick="this.style.display='none'; Codehighlighter1_295_1342_Closed_Text.style.display='none'; Codehighlighter1_295_1342_Open_Image.style.display='inline'; Codehighlighter1_295_1342_Open_Text.style.display='inline';" 
            src="在JSF中实现分页(二).files/ContractedBlock.gif" align=top></SPAN><SPAN 
            id=Codehighlighter1_295_1342_Closed_Text 
            style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
            src="在JSF中实现分页(二).files/dot.gif"></SPAN><SPAN 
            id=Codehighlighter1_295_1342_Open_Text><SPAN 
            style="COLOR: #000000">{<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
            style="COLOR: #0000ff">private</SPAN><SPAN 
            style="COLOR: #000000">&nbsp;</SPAN><SPAN 
            style="COLOR: #0000ff">int</SPAN><SPAN 
            style="COLOR: #000000">&nbsp;datasetSize;<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
            style="COLOR: #0000ff">private</SPAN><SPAN 
            style="COLOR: #000000">&nbsp;</SPAN><SPAN 
            style="COLOR: #0000ff">int</SPAN><SPAN 
            style="COLOR: #000000">&nbsp;startRow;<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
            style="COLOR: #0000ff">private</SPAN><SPAN 
            style="COLOR: #000000">&nbsp;List&nbsp;data;<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" align=top><BR><IMG 
            id=Codehighlighter1_368_746_Open_Image 
            onclick="this.style.display='none'; Codehighlighter1_368_746_Open_Text.style.display='none'; Codehighlighter1_368_746_Closed_Image.style.display='inline'; Codehighlighter1_368_746_Closed_Text.style.display='inline';" 
            src="在JSF中实现分页(二).files/ExpandedSubBlockStart.gif" align=top><IMG 
            id=Codehighlighter1_368_746_Closed_Image style="DISPLAY: none" 
            onclick="this.style.display='none'; Codehighlighter1_368_746_Closed_Text.style.display='none'; Codehighlighter1_368_746_Open_Image.style.display='inline'; Codehighlighter1_368_746_Open_Text.style.display='inline';" 
            src="在JSF中实现分页(二).files/ContractedSubBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
            id=Codehighlighter1_368_746_Closed_Text 
            style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**&nbsp;*/</SPAN><SPAN 
            id=Codehighlighter1_368_746_Open_Text><SPAN 
            style="COLOR: #008000">/**</SPAN><SPAN 
            style="COLOR: #008000"><BR><IMG src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Create&nbsp;an&nbsp;object&nbsp;representing&nbsp;a&nbsp;sublist&nbsp;of&nbsp;a&nbsp;dataset.<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</SPAN><SPAN 
            style="COLOR: #808080">@param</SPAN><SPAN 
            style="COLOR: #008000">&nbsp;datasetSize<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is&nbsp;the&nbsp;total&nbsp;number&nbsp;of&nbsp;matching&nbsp;rows&nbsp;available.<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</SPAN><SPAN 
            style="COLOR: #808080">@param</SPAN><SPAN 
            style="COLOR: #008000">&nbsp;startRow<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is&nbsp;the&nbsp;index&nbsp;within&nbsp;the&nbsp;complete&nbsp;dataset&nbsp;of&nbsp;the&nbsp;first&nbsp;element<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;in&nbsp;the&nbsp;data&nbsp;list.<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</SPAN><SPAN 
            style="COLOR: #808080">@param</SPAN><SPAN 
            style="COLOR: #008000">&nbsp;data<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is&nbsp;a&nbsp;list&nbsp;of&nbsp;consecutive&nbsp;objects&nbsp;from&nbsp;the&nbsp;dataset.<BR><IMG 
            src="在JSF中实现分页(二).files/ExpandedSubBlockEnd.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
            style="COLOR: #008000">*/</SPAN></SPAN><SPAN 
            style="COLOR: #000000"><BR><IMG src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
            style="COLOR: #0000ff">public</SPAN><SPAN 
            style="COLOR: #000000">&nbsp;DataPage(</SPAN><SPAN 
            style="COLOR: #0000ff">int</SPAN><SPAN 
            style="COLOR: #000000">&nbsp;datasetSize,&nbsp;</SPAN><SPAN 
            style="COLOR: #0000ff">int</SPAN><SPAN 
            style="COLOR: #000000">&nbsp;startRow,&nbsp;List&nbsp;data)<BR><IMG 
            id=Codehighlighter1_808_893_Open_Image 
            onclick="this.style.display='none'; Codehighlighter1_808_893_Open_Text.style.display='none'; Codehighlighter1_808_893_Closed_Image.style.display='inline'; Codehighlighter1_808_893_Closed_Text.style.display='inline';" 
            src="在JSF中实现分页(二).files/ExpandedSubBlockStart.gif" align=top><IMG 
            id=Codehighlighter1_808_893_Closed_Image style="DISPLAY: none" 
            onclick="this.style.display='none'; Codehighlighter1_808_893_Closed_Text.style.display='none'; Codehighlighter1_808_893_Open_Image.style.display='inline'; Codehighlighter1_808_893_Open_Text.style.display='inline';" 
            src="在JSF中实现分页(二).files/ContractedSubBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
            id=Codehighlighter1_808_893_Closed_Text 
            style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
            src="在JSF中实现分页(二).files/dot.gif"></SPAN><SPAN 
            id=Codehighlighter1_808_893_Open_Text><SPAN 
            style="COLOR: #000000">{<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
            style="COLOR: #0000ff">this</SPAN><SPAN 
            style="COLOR: #000000">.datasetSize&nbsp;</SPAN><SPAN 
            style="COLOR: #000000">=</SPAN><SPAN 
            style="COLOR: #000000">&nbsp;datasetSize;<BR><IMG 
            src="在JSF中实现分页(二).files/InBlock.gif" 
            align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
            style="COLOR: #0000ff">this</SPAN><SPAN 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -