JSF动态生成固定表头和行标的DataTable

这个例子在jsf1.1下通过。JSF动态生成DataTable, 希望可以供大家学习和参考。

创新互联建站专业为企业提供浑南网站建设、浑南做网站、浑南网站设计、浑南网站制作等企业网站建设、网页设计与制作、浑南企业网站模板建站服务,十载浑南做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

自己在写JSF动态生成DataTable的时候也查阅了很多相关文章, 以及实现固定表头等等。

在解决固定表头问题上我是用的两张表(加行标是3张表)实现的, 因为我发现如果用JSF1.1的化实现固定表头几乎不可能(如果有人有好的想法, 比如用JS比较在行的朋友请告诉我解决方法, 谢谢)

实现给每个Header加上一个CommandLink的时候我遇到了很大的问题, 就是无论如何通过JSF动态生成的这些CommandLink都没有办法触发事件(并不报错), 这个问题足足折磨了我3天。。。

***终于发现问题的所在, 是因为我在生成CommandLink的时候没有给每个CommandLink  SetID。。。 就加上这句话,问题立马解决。

我原来的代码是链接数据库的, 但是这样的化大家也没有办法参考, 所以我对代码少加修改, 就算是个小例子吧, 可重用。

希望大家对我的代码提出JSF动态生成固定表头和行标的DataTable的意见,一起进步,谢谢。

  1. <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> 
  2. <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> 
  3.  language="JavaScript"> 
  4.   var tdW;  
  5.   //Scroll  
  6.   function f_scroll(Col_T,Row_T,DivNm){  
  7.     if(Col_T!=''){  
  8.       document.getElementById(Col_T).scrollLeft = document.getElementById(DivNm).scrollLeft;  
  9.     }  
  10.     if(Row_T!=''){  
  11.       document.getElementById(Row_T).scrollTop = document.getElementById(DivNm).scrollTop;  
  12.     }  
  13.   }  
  14. Script> 
  15.  
  16.   
  17.    
  18.    </strong>TABLE<strong> title></strong>  </li> <li>  <strong><link</strong> rel="stylesheet" type="text/css" href="styles.css"<strong>></strong>  </li> <li> <strong> head></strong>  </li> <li><strong><body></strong>  </li> <li> <strong><h:form></strong>  </li> <li>  <<strong>font</strong> size="2" color="black"  </li> <li>    style="position:absolute; left: 35; top: 5; width:200; height:20"<strong>></strong>  </li> <li>      <strong><h:outputText</strong> value="Please Enter:" <strong>/></strong> <strong> font></strong>  </li> <li>   <strong><h:inputText</strong> value="" size="20"  </li> <li>      style="position:absolute; left: 110; top: 5; width:150; height:20" <strong>/></strong>  </li> <li>   <strong><h:commandButton</strong> value="Search" action=""  </li> <li>      style="position:absolute; left: 270; top: 5; width:50; height:20" <strong>/></strong></li> <li><strong><table</strong> BORDER=0  </li> <li>      STYLE="POSITION: ABSOLUTE; LEFT: 0px; TOP: 30px; right: 0px; bottom: 0px;"<strong>></strong>  </li> <li>  <strong><tr></strong>  </li> <li>      <strong><td</strong> STYLE="text-align: right;"<strong>></strong>  </li> <li>             </li> <li>              </li> <li>       <strong> td></strong>  </li> <li>     <strong><td></strong>  </li> <li>            </li> <li>         <strong><Div</strong> ID="Table2"  </li> <li>         STYLE="position: relative; top: 0; border-left: 0.5pt solid black;   </li> <li>            border-right: 0.5pt solid black; height: 17.75px; width: 285px; overflow-x: hidden;"<strong>></strong>  </li> <li>          <strong><h:dataTable</strong> value="#{myBean.myHeader}" var="myHeader"  </li> <li>              binding="#{myBean.headerDataTable}" bgcolor="white" border="1"  </li> <li>              cellspacing="1" rendered="true" styleClass="orders"  </li> <li>              headerClass="ordersHeader" rowClasses="evenColumn,oddColumn"  </li> <li>              style="position:absolute; left: 0; top: 0;    </li> <li>                    width: 100; height: 10; border-collapse:collapse;"   </li> <li>           id="ree"<strong>></strong>  </li> <li>         <strong> h:dataTable></strong>  </li> <li>       <strong> Div></strong>  </li> <li>          </li> <li>    <strong> td></strong>  </li> <li><strong> tr></strong>  </li> <li><strong><tr></strong>  </li> <li>  <strong><td</strong> STYLE="vertical-align: top;"<strong>></strong>  </li> <li>        </li> <li>   <strong><Div</strong> ID="Table3"  </li> <li>      STYLE="border-bottom: 0.5pt solid black; border-top: 0.5pt solid black;    </li> <li>       width: 25.5px; height: 265px; overflow-y: hidden; position: relative; left: 0;"<strong>></strong>  </li> <li>    <strong><h:dataTable</strong> value="#{myBean.myNum}" var="myNum"  </li> <li>       binding="#{myBean.numDataTable}" bgcolor="white" border="1"  </li> <li>       cellspacing="1" rendered="true" styleClass="orders"  </li> <li>       headerClass="ordersHeader" rowClasses="evenColumn,oddColumn"  </li> <li>       style="position:absolute; left: 0; top: 0; width: 32; height: 5; border-collapse:collapse;"  </li> <li>       id="dee"<strong>></strong>  </li> <li>         <strong> h:dataTable></strong>  </li> <li>           <strong> Div></strong>  </li> <li>                </li> <li>          <strong> td></strong>  </li> <li>          <strong><td</strong> STYLE="vertical-align: top;"<strong>></strong>  </li> <li>               </li> <li>          <strong><Div</strong> ID="Table4" onScroll="f_scroll('Table2','Table3','Table4');"  </li> <li>             STYLE="height: 281px; width: 300px; overflow-y: scroll; overflow-x: scroll;"<strong>></strong>  </li> <li>          <strong><h:dataTable</strong> value="#{myBean.myList}" var="myItem"  </li> <li>              binding="#{myBean.dynamicDataTable}" bgcolor="white" border="1"  </li> <li>               cellspacing="1" rendered="true" styleClass="orders"  </li> <li>               headerClass="ordersHeader" rowClasses="evenColumn,oddColumn"  </li> <li>              style="position:absolute; left: 0; top: 0; width: 100;                                                                            height: 5; border-collapse:collapse;"<strong>></strong>  </li> <li>             <strong> h:dataTable></strong>  </li> <li>           <strong> Div></strong>  </li> <li>                </li> <li>        <strong> td></strong>  </li> <li>       <strong> tr></strong>  </li> <li>      <strong> table></strong>  </li> <li>     <strong> h:form></strong>  </li> <li>    <strong> body></strong>  </li> <li>  <strong> f:view></strong>  </li> <li><strong> html></strong></li> </ol> <p> 分享文章:<a href="http://www.kswsj.com/qtweb/news1/185701.html">JSF动态生成固定表头和行标的DataTable</a> <br> 本文URL:<a href="http://www.kswsj.com/qtweb/news1/185701.html">http://www.kswsj.com/qtweb/news1/185701.html</a> </p> <p> 网站建设、网络推广公司-成都快上网,一家网站设计、网站制作公司;服务项目有等 </p> <p class="adpic"> <a href="https://www.cdcxhl.com/service/ad.html" target="_blank" class="ad">广告</a> <a href="" target="_blank" class="adimg"><img src=""></a> </p> <p class="copy"> 声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: <a href="http://www.kswsj.com/" target="_blank">成都快上网</a> </p> </div> <div class="newsmorelb"> <p>成都快上网科技猜您喜欢</p> <ul> <li> <a href="/qtweb/news0/185700.html">网站有国外的服务器吗?(服务器在国外?)</a> </li><li> <a href="/qtweb/news49/185699.html">性Redis线程安全性分析(redis 的线程安全)</a> </li><li> <a href="/qtweb/news48/185698.html">php如何记住自动登录的密码</a> </li><li> <a href="/qtweb/news47/185697.html">域名必须实名认证么</a> </li><li> <a href="/qtweb/news46/185696.html">cpu怎么散热?(CPU怎么散热的)</a> </li><li> <a href="/qtweb/news45/185695.html">Linux下Web编程:掌握让程序飞起来的技能(linuxweb编程)</a> </li><li> <a href="/qtweb/news44/185694.html">如何连接FTP服务器?(怎么连接ftp服务器)</a> </li><li> <a href="/qtweb/news43/185693.html">企业安全产品测评之FireWall-1</a> </li><li> <a href="/qtweb/news42/185692.html">安装配置Mail服务器_搭建容器运行环境</a> </li> </ul> </div> </div> <div class="col-lg-3 noneb"> <div class="bkright" style="margin-top: 0"> <p><a href="https://www.cdcxhl.com/news/waimaojianshe/">外贸网站建设知识</a></p> <ul> <li> <a class="text_overflow" href="/qtweb/news4/17654.html">win10怎么查看安装日志?(windows10查看系统日志)</a> </li><li> <a class="text_overflow" href="/qtweb/news44/59694.html">花生壳二级域名怎么用?(花生壳买的域名怎么用啊)</a> </li><li> <a class="text_overflow" href="/qtweb/news32/321732.html">什么是强制类型转换符</a> </li><li> <a class="text_overflow" href="/qtweb/news13/546263.html">Linux分支系统:探索开源世界的不同之处(linux的分支)</a> </li><li> <a class="text_overflow" href="/qtweb/news44/280894.html">python中参数类型</a> </li><li> <a class="text_overflow" href="/qtweb/news13/230813.html">c语言中怎么使用int</a> </li><li> <a class="text_overflow" href="/qtweb/news8/16858.html">如何建立免费网站,如何自己建立一个网站</a> </li><li> <a class="text_overflow" href="/qtweb/news25/2525.html">监听风云|Inotify实现原理</a> </li><li> <a class="text_overflow" href="/qtweb/news31/458981.html">免备案便宜的虚拟主机怎么租用</a> </li><li> <a class="text_overflow" href="/qtweb/news11/507961.html">决定韩国服务器价格的因素有哪些</a> </li><li> <a class="text_overflow" href="/qtweb/news43/429593.html">simulink中用buffer模块报错</a> </li><li> <a class="text_overflow" href="/qtweb/news20/2470.html">带你了解JavaScript反调试技巧</a> </li><li> <a class="text_overflow" href="/qtweb/news44/373544.html">生成式AI颠覆传统数据库的十种方式</a> </li><li> <a class="text_overflow" href="/qtweb/news16/470566.html">windows10屏保密码?(windows10屏保密码设置)</a> </li><li> <a class="text_overflow" href="/qtweb/news39/181539.html">服务器状态不对-云服务器问题</a> </li> </ul> </div> <div class="bkright tag"> <p><a href="https://www.cdcxhl.com/hangye/" target="_blank">分类信息网</a></p> <ul> <li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/banjia/" target="_blank">搬家公司</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/gsdb/" target="_blank">工商代办</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/fadianji/" target="_blank">柴油发电机</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/bgcl/" target="_blank">办公窗帘</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/bxgds/" target="_blank">不锈钢雕塑</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/xuanchuanpian/" target="_blank">宣传片制作</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/hntjbc/" target="_blank">混凝土搅拌罐车</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/zufadianji/" target="_blank">发电机租赁</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/ggtg/" target="_blank">广告推广</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/snjbc/" target="_blank">水泥搅拌车</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/suliaodai/" target="_blank">塑料袋</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/xiangsu/" target="_blank">橡塑保温</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/fadianjihs/" target="_blank">发电机回收</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/ruanzhuangsj/" target="_blank">软装设计</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/bolixiufu/" target="_blank">汽车玻璃修复</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/zaomaoji/" target="_blank">凿毛机</a> </li> </ul> </div> </div> </div> <div class="carousel-inner linkbg" style="background: #fff"> <div class="container"> <a href="http://www.jljierui.cn/" target="_blank">时嘉做网站</a>    <a href="http://www.sdhchd.com/" target="_blank">成都柴油发电机租赁</a>    <a href="http://www.cqcxhl.com/service/education.html" target="_blank">重庆教育培训网站建设</a>    <a href="http://www.cdkjz.cn/wangzhan/jituan/" target="_blank">成都集团网站建设</a>    <a href="http://www.lswzjz.com/" target="_blank">乐山网站建设</a>    <a href="http://www.cdhuace.com/fuwu.html" target="_blank">成都名片印刷厂</a>    <a href="http://www.bjjike.cn/" target="_blank">红光高低压开关厂</a>    <a href="http://www.kswcd.com/" target="_blank">定制网站</a>    <a href="http://www.75109.cn/" target="_blank">成都工商服务</a>    <a href="http://www.cdtuopan.cn/" target="_blank">成都木托盘</a>    <a href="http://www.cxhlcq.com/qiye/" target="_blank">重庆企业网站建设</a>    <a href="http://www.szjierui.cn/" target="_blank">主动防护网</a>    <a href="http://www.cdhuace.com/zhangui.html" target="_blank">四川成都展柜定制厂家</a>    <a href="http://www.gawzjs.com/" target="_blank">广安网站制作公司</a>    <a href="http://www.zzfdjwx.com/" target="_blank">宏鑫宇康</a>    <a href="http://www.csruizhi.cn/" target="_blank">崇州网站制作</a>    <a href="http://www.njjike.cn/" target="_blank">成都办公窗帘</a>    <a href="https://www.cdcxhl.cn/ " target="_blank">香港云虚拟主机</a>    <a href="http://www.cdxwcx.cn/tuoguan/mianyang.html" target="_blank">绵阳电信服务器托管</a>    <a href="http://m.cdcxhl.cn/seo/ " target="_blank">营销网站建设</a>     </div> </div> <footer> <div class="carousel-inner footjz"> <div class="container"> <i class="icon iconfont zbw"></i> 品质网站建设 <i class="icon iconfont"></i> 多平台展现 <i class="icon iconfont"></i> 600元建站 <i class="icon iconfont"></i> 高效快速 <i class="icon iconfont"></i> 专业用心服务 <button type="button" class="btn btn-default btn-lg" onClick="window.location.href='tencent://message/?uin=631063699&Site=&Menu=yes'"> 立即开始600元网站建设</button> <button type="button" class="btn btn-default btn-xs" onClick="window.location.href='tencent://message/?uin=631063699&Site=&Menu=yes'"> 600元企业网站建设</button> </div> </div> <div class="carousel-inner bqsy"> <div class="container"> <div class="lxfs"> <h4 class="yutelnone">028-86922220 13518219792</h4> <h4 class="yutelblock"><a href="tel:02886922220">028-86922220</a> <a href="tel:13518219792">13518219792</a></h4> <a class="btn btn-default" href="tencent://message/?uin=532337155&Site=&Menu=yes" role="button">网站建设<span>QQ</span>:532337155</a> <a class="btn btn-default" href="tencent://message/?uin=631063699&Site=&Menu=yes" role="button">营销推广<span>QQ</span>:631063699</a> <a class="btn btn1 btn-default" href="mqqwpa://im/chat?chat_type=wpa&uin=532337155&version=1&src_type=web&web_src=oicqzone.com" role="button">网站制作<span>QQ</span>:532337155</a> <a class="btn btn1 btn-default" href="mqqwpa://im/chat?chat_type=wpa&uin=631063699&version=1&src_type=web&web_src=oicqzone.com" role="button">营销推广<span>QQ</span>:631063699</a> <a class="btn btn-default nonea" href="tencent://message/?uin=1683211881&Site=&Menu=yes" role="button">售后QQ:1683211881</a> <div class="dz">成都快上网专注: <a href="http://www.kswsj.com/" target="_blank">成都网站制作</a> <a href="http://www.kswsj.com/" target="_blank">网站设计</a> <a href="http://www.kswsj.com/" target="_blank">成都网站建设</a> <address>地址:成都太升南路288号锦天国际A幢10楼</address> </div> </div> <div class="bzdh dz"><img src="https://www.cdcxhl.com/imges/bottom_logo.png" alt="创新互联"> <p><a href="https://www.cdcxhl.com/menu.html" target="_blank">成都创新互联科技有限公司</a><br> Tel:028-86922220(7x24h)</p></div> </div> </div> </footer> </body> </html> <script> $.getJSON ("../../qtwebpic.txt", function (data) { var jsonContent = { "featured":data } var random = jsonContent.featured[Math.floor(Math.random() * jsonContent.featured.length)]; $(".adpic .adimg").attr("href",random.link) $(".adpic img").attr("src",random.pic); }) </script>