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

📄 在jsf中实现分页 jsf- 实现 java● 咖啡馆 -- jsf中文论坛.htm

📁 jsf分页处理, 很 好的例子, 可以很方便的移植
💻 HTM
📖 第 1 页 / 共 5 页
字号:
  <TR>
    <TD width=34 
    background="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/left.gif"><IMG 
      src="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/left.gif"></TD>
    <TD><BR><!----><!---->
      <TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
        <TBODY>
        <TR>
          <TD align=left><IMG alt="" 
            src="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/home.gif" 
            align=absBottom> <SPAN class=bold><A 
            href="http://www.hexiao.cn/jsf/index.php">Java● 咖啡馆 -- 
            JSF中文论坛</A>&nbsp;-&gt;&nbsp;<A 
            href="http://www.hexiao.cn/jsf/thread.php?fid=13&amp;page=">JSF- 
            实现</A>&nbsp;-&gt;&nbsp;在JSF中实现分页</SPAN></TD>
          <TD align=right>您是本帖的第 <SPAN class=bold>601</SPAN> 个阅读者</TD></TR>
        <TR>
          <TD height=5></TD></TR></TBODY></TABLE><BR><!---->
      <TABLE cellSpacing=0 cellPadding=1 width="100%" align=center border=0>
        <TBODY>
        <TR>
          <TD align=left><SPAN class=bold>本版只有一页</SPAN></TD>
          <TD align=right><A 
            href="http://www.hexiao.cn/jsf/post.php?fid=13"><IMG 
            src="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/post.gif" 
            border=0></A> <A 
            href="http://www.hexiao.cn/jsf/post.php?action=vote&amp;fid=13"><IMG 
            src="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/vote.gif" 
            border=0></A> <A 
            href="http://www.hexiao.cn/jsf/post.php?action=reply&amp;fid=13&amp;tid=13"><IMG 
            src="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/reply.gif" 
            border=0></A> </TD></TR></TBODY></TABLE>
      <TABLE cellSpacing=0 cellPadding=0 width="100%" align=center 
      bgColor=#e5e3e3 border=0>
        <TBODY>
        <TR>
          <TD height=1></TD></TR></TBODY></TABLE>
      <TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
        <TBODY>
        <TR>
          <TD vAlign=center width=1 bgColor=#e5e3e3 height=22></TD>
          <TD vAlign=center align=left width=*>
            <TABLE cellSpacing=0 cellPadding=1 width="100%" border=0>
              <TBODY>
              <TR>
                <TD class=head vAlign=center align=left><SPAN 
                  class=bold>&raquo;&nbsp;本页主题</SPAN>: 在JSF中实现分页</TD>
                <TD class=head align=right><A class=headurl 
                  onfocus=this.blur() 
                  onclick="window.external.AddFavorite('http://www.hexiao.cn/jsf/read.php?&amp;fid=13&amp;tid=13', 'Java● 咖啡馆 -- JSF中文论坛--在JSF中实现分页')" 
                  href="http://www.hexiao.cn/jsf/read.php?fid=13&amp;tid=13&amp;searchword=%B7%D6%D2%B3#">加为IE收藏</A>&nbsp;| 
                  <A class=headurl 
                  href="http://www.hexiao.cn/jsf/job.php?action=favor&amp;job=favor&amp;fid=13&amp;tid=13">收藏主题</A>&nbsp;| 
                  <A class=headurl 
                  href="http://www.hexiao.cn/jsf/job.php?rd_previous=1&amp;fid=13&amp;tid=13&amp;fpage=&amp;goto=previous">上一主题 
                  </A>| <A class=headurl 
                  href="http://www.hexiao.cn/jsf/job.php?rd_previous=1&amp;fid=13&amp;tid=13&amp;fpage=&amp;goto=next">下一主题</A> 
                </TD></TR></TBODY></TABLE></TD>
          <TD vAlign=center width=1 bgColor=#e5e3e3 
      height=22></TD></TR></TBODY></TABLE>
      <TABLE cellSpacing=0 cellPadding=0 width="100%" align=center 
      bgColor=#e5e3e3 border=0>
        <TBODY>
        <TR>
          <TD height=1></TD></TR></TBODY></TABLE><!--<!--帖子模版-->
      <TABLE style="TABLE-LAYOUT: fixed; WORD-WRAP: break-word" cellSpacing=1 
      cellPadding=0 width="100%" align=center bgColor=#e5e3e3>
        <TBODY>
        <TR>
          <TD 
          style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px" 
          vAlign=top width="20%" bgColor=#ffffff height="100%"><FONT 
            face=Gulim color=#000066><SPAN class=bold>icess</SPAN></FONT> 
            <TABLE style="TABLE-LAYOUT: fixed" cellSpacing=0 cellPadding=0 
            width="95%" border=0>
              <TBODY>
              <TR>
                <TD align=middle><BR><IMG 
                  src="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/0.gif" 
                  border=0></TD></TR></TBODY></TABLE><BR><IMG 
            src="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/10super.gif"><BR>级别: 
            <FONT color=#555555>论坛管理员<IMG alt=该用户目前不在线 
            src="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/offonline.gif"></FONT><BR>发贴: 
            <FONT color=green><SPAN class=bold>618</SPAN></FONT> (精华:<FONT 
            color=green><SPAN class=bold>0</SPAN></FONT>)<BR>威望: <FONT 
            color=#984b98><SPAN class=bold>268</SPAN></FONT><BR>咖啡豆: <FONT 
            color=red><SPAN 
            class=bold>2054</SPAN></FONT><BR>注册时间:2006-06-01<BR>最后登陆:2007-03-24 
          </TD>
          <TD vAlign=top width="80%" bgColor=#ffffff height="100%">
            <TABLE style="TABLE-LAYOUT: fixed; WORD-WRAP: break-word" 
            height="100%" cellSpacing=0 cellPadding=4 width="99%" 
              align=center><TBODY>
              <TR>
                <TD vAlign=top width="91%" bgColor=#ffffff colSpan=5><A 
                  href="http://www.hexiao.cn/jsf/profile.php?action=show&amp;username=icess"><IMG 
                  alt=查看作者资料 
                  src="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/profile.gif" 
                  align=absMiddle border=0></A> <A 
                  href="http://www.hexiao.cn/jsf/message.php?action=write&amp;msgid=icess"><IMG 
                  alt=发送短消息 
                  src="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/message.gif" 
                  align=absMiddle border=0></A> <A title=发送邮件 
                  href="http://www.hexiao.cn/jsf/sendemail.php?username=icess"><IMG 
                  src="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/email.gif" 
                  align=absMiddle border=0></A> <A 
                  href="http://www.hexiao.cn/jsf/sendemail.php?action=tofriend&amp;fid=13&amp;tid=13&amp;fpage="><IMG 
                  alt=推荐此贴 
                  src="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/emailto.gif" 
                  align=absMiddle border=0></A> <A 
                  href="http://www.hexiao.cn/jsf/post.php?action=quote&amp;fid=13&amp;tid=13&amp;article=0"><IMG 
                  alt=引用回复这个贴子 
                  src="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/quote.gif" 
                  align=absMiddle border=0></A> <A 
                  href="http://www.hexiao.cn/jsf/post.php?action=modify&amp;fid=13&amp;tid=13&amp;article=0"><IMG 
                  alt=删除或编辑改帖子 
                  src="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/edit.gif" 
                  align=absMiddle border=0></A> 【字体:<A 
                  onclick="text0.style.fontSize='16px';" 
                  href="javascript:;">大</A> <A 
                  onclick="text0.style.fontSize='14px';" 
                  href="javascript:;">中</A> <A 
                  onclick="text0.style.fontSize='12px';" 
                  href="javascript:;">小</A>】 
                  <HR width="100%" color=#e5e3e3 SIZE=1>
                  <IMG src="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/11.gif" 
                  align=left border=0> <SPAN 
                  class=tpc_title>&nbsp;在JSF中实现分页</SPAN><BR><SPAN 
                  class=tpc_content id=text0><BR><BR>转贴于<A 
                  href="http://www.blogjava.net/steady" 
                  target=_blank>www.blogjava.net/steady</A> 
                  的blog<BR><BR>对于大多数Web应用,<B 
                  style="COLOR: red; BACKGROUND-COLOR: #ffff66">分页</B></FONT>都是必不可少的功能,当然在JSF中也一样,我在这里用两篇文章介绍两种方法来展示一下,如何在JSF中实现<B 
                  style="COLOR: red; BACKGROUND-COLOR: #ffff66">分页</B></FONT>。本文假定你已经对JSF有了一些简单的了解,懂得基本配置和使用,并建立起一个blank项目。<BR><BR>&nbsp; 
                  Myfaces是Apache基金会中的一个一级项目,除了实现JSF标准外,做了很多的扩展工作,在Myfaces包中有一个扩展包Tomahawk,我们将主要使用其中的两个Component实现<B 
                  style="COLOR: red; BACKGROUND-COLOR: #ffff66">分页</B></FONT>:一个是&lt;t:dataTable&gt;,另一个是&lt;t:dataScroller&gt;,在第一篇里面,我们简易的组合这两个Component来实现一种简单,但并不高效的<B 
                  style="COLOR: red; BACKGROUND-COLOR: #ffff66">分页</B></FONT>。<BR><BR>&nbsp; 
                  下面的例子来自于Myfaces-Sample,我省去了其中和<B 
                  style="COLOR: red; BACKGROUND-COLOR: #ffff66">分页</B></FONT>逻辑无关的内容,详细的例子可以下载Myfaces-Sample包或者访问<A 
                  href="http://www.irian.at/myfaces/home.jsf" 
                  target=_blank>http://www.irian.at/myfaces/home.jsf</A> 
                  查看。<BR><BR>&nbsp; 第一部分:dataTable<BR><BR><BR><FONT 
                  color=red>以下是代码:</FONT><BR><TEXTAREA class=java name=code rows=15 cols=100>&lt;t:dataTable id="data"
 &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp; var="car"
 &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp; value="#{pagedSort.cars}"
 &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp; rows="10"&gt;
 &nbsp;  ……
&lt;/t:dataTable&gt;

</TEXTAREA><BR><BR>在这一部分中,dataTable绑定了一个backing bean - 
                  pagedSort中的cars属性,我们可以在这个属性中加入数据访问逻辑,从数据库或者其他来源取得用于显示的数据。比如我们可以通过Hibernate获取一个List,其中包含有我们用于显示的POJOs。<BR><BR>注意,dataTable中的rows属性指的是每页的行数,是必须指定的,否则是无法进行<B 
                  style="COLOR: red; BACKGROUND-COLOR: #ffff66">分页</B></FONT>的,如果在项目中会使用固定行数的<B 
                  style="COLOR: red; BACKGROUND-COLOR: #ffff66">分页</B></FONT>,建议把这个值写在BaseBackingBean中,并暴露一个property,供页面调用,所以每次在页面中就可以这么写#{backingBean.pageSize}。<BR><BR><BR><BR>第二部分:dataScroller<BR><BR><BR><BR><FONT 
                  color=red>以下是代码:</FONT><BR><TEXTAREA class=java name=code rows=15 cols=100>&lt;t:dataScroller id="scroll_1"
 &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp; for="data"
 &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp; fastStep="10"
 &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp; paginator="true"
 &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp; paginatorMaxPages="9"&gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp; &lt;f:facet name="first" &gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &lt;t:graphicImage url="images/arrow-first.gif" border="1" /&gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp; &lt;/f:facet&gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp; &lt;f:facet name="last"&gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &lt;t:graphicImage url="images/arrow-last.gif" border="1" /&gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp; &lt;/f:facet&gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp; &lt;f:facet name="previous"&gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &lt;t:graphicImage url="images/arrow-previous.gif" border="1" /&gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp; &lt;/f:facet&gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp; &lt;f:facet name="next"&gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &lt;t:graphicImage url="images/arrow-next.gif" border="1" /&gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp; &lt;/f:facet&gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp; &lt;f:facet name="fastforward"&gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &lt;t:graphicImage url="images/arrow-ff.gif" border="1" /&gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp; &lt;/f:facet&gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp; &lt;f:facet name="fastrewind"&gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &lt;t:graphicImage url="images/arrow-fr.gif" border="1" /&gt;
 &nbsp;  &nbsp;  &nbsp;  &nbsp; &lt;/f:facet&gt;

</TEXTAREA><BR><BR>这里定义了我们用于<B 
                  style="COLOR: red; BACKGROUND-COLOR: #ffff66">分页</B></FONT>的&lt;t:dataScroller&gt;,最主要的是配置该<B 
                  style="COLOR: red; BACKGROUND-COLOR: #ffff66">分页</B></FONT>Component针对哪个dataTable进行<B 
                  style="COLOR: red; BACKGROUND-COLOR: #ffff66">分页</B></FONT>的“for”属性,该属性与dataTable绑定,并对其进行<B 
                  style="COLOR: red; BACKGROUND-COLOR: #ffff66">分页</B></FONT>,在这里,绑定了第一部分中的id="data"的dataTable,下面有很多的&lt;t:facet&gt;是指定<B 
                  style="COLOR: red; BACKGROUND-COLOR: #ffff66">分页</B></FONT>的导航样式的,这里使用了图片作为导航,可以把他们改成文字形式的导航。<BR><BR>&nbsp; 
                  当然这只是最简单,也是一种不推荐的<B 
                  style="COLOR: red; BACKGROUND-COLOR: #ffff66">分页</B></FONT>方式,因为在每次进行<B 
                  style="COLOR: red; BACKGROUND-COLOR: #ffff66">分页</B></FONT>的时候,将会从数据库中取回所有的记录放入List中,然后,dataScroller在对这个List进行<B 
                  style="COLOR: red; BACKGROUND-COLOR: #ffff66">分页</B></FONT>,如果在数据量很大的情况下,这种方式显然是不符合要求的,假设每条记录占用1k内存,数据库中有100万条记录,每次要把这个List全部读取出来将占用1G内存。我们需要一种Load 
                  on demand方式的读取,也就是只在需要查看某页的时候读取该页的数据。<BR><BR>&nbsp; 
                  另外一方面,JSF的生命周期中有多个阶段会调用到#{pagedSort.cars}中对应的方法,如果在这里调用了数据访问逻辑,就会在只显示一次页面的情况下进行多次数据库操作,也是相当的耗费资源的。<BR><BR>&nbsp; 
                  所以我们需要有更好的<B 
                  style="COLOR: red; BACKGROUND-COLOR: #ffff66">分页</B></FONT>方式去解决以上问题,下一篇我将介绍另一种方法以改善这些问题。<BR><BR><BR><BR></SPAN></TD></TR>
              <FORM method=post>
              <TR vAlign=bottom bgColor=#ffffff>
                <TD colSpan=5><BR><!----><IMG 
                  src="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/sigline.gif" 
                  border=0> <BR>程序<BR><!----><FONT color=red>[0楼]</FONT> | 
                  IP:已记录| <SPAN class=bold>Posted:</SPAN>2006-09-8 11:07 AM|</TD>
                <TD vAlign=bottom align=right><A 
                  href="javascript:scroll(0,0)"><IMG alt=回到顶端 
                  src="在JSF中实现分页 JSF- 实现 Java● 咖啡馆 -- JSF中文论坛.files/top.gif" 
                  border=0></A></TD></TR></FORM></TBODY></TABLE></TD></TR></TBODY></TABLE>
      <TABLE width="100%" align=center>
        <TBODY>
        <TR>
          <TD height=1></TD></TR></TBODY></TABLE><!--<!--帖子模版-->
      <TABLE style="TABLE-LAYOUT: fixed; WORD-WRAP: break-word" cellSpacing=1 
      cellPadding=0 width="100%" align=center bgColor=#e5e3e3>
        <TBODY>
        <TR>
          <TD 
          style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px" 
          vAlign=top width="20%" bgColor=#f7f7f7 height="100%"><FONT 
            face=Gulim color=#000066><SPAN class=bold>icess</SPAN></FONT> 
            <TABLE style="TABLE-LAYOUT: fixed" cellSpacing=0 cellPadding=0 
            width="95%" border=0>

⌨️ 快捷键说明

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