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.36103.cn/qtweb/news8/30558.html">JSF动态生成固定表头和行标的DataTable</a> <br> 浏览地址:<a href="http://www.36103.cn/qtweb/news8/30558.html">http://www.36103.cn/qtweb/news8/30558.html</a> </p> <p> 网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等 </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="https://www.cdcxhl.com/" target="_blank">创新互联</a> </p> </div> <div class="newsmorelb"> <p>猜你还喜欢下面的内容</p> <ul> <li> <a href="/qtweb/news7/30557.html">性Redis线程安全性分析(redis 的线程安全)</a> </li><li> <a href="/qtweb/news6/30556.html">php如何记住自动登录的密码</a> </li><li> <a href="/qtweb/news5/30555.html">企业安全产品测评之FireWall-1</a> </li><li> <a href="/qtweb/news4/30554.html">安装配置Mail服务器_搭建容器运行环境</a> </li><li> <a href="/qtweb/news3/30553.html">Linux三级页表:分页式内存管理的小而伟大(linux三级页表)</a> </li><li> <a href="/qtweb/news2/30552.html">梁崎桃李画册里弟子有谁?(青岛网站画册设计,品牌画册设计网站)</a> </li><li> <a href="/qtweb/news1/30551.html">maya蒙皮后报错崩溃</a> </li><li> <a href="/qtweb/news0/30550.html">域名服务器检测的有什么方法</a> </li><li> <a href="/qtweb/news49/30549.html">负载均衡的区别?服务器负载均衡器</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/daohang/">网站导航知识</a></p> <ul> <li> <a class="text_overflow" href="/qtweb/news20/33220.html">newbing怎么防止跳转到国内?(如何避免跳转中国网站)</a> </li><li> <a class="text_overflow" href="/qtweb/news40/6440.html">如何用云主机创建网站</a> </li><li> <a class="text_overflow" href="/qtweb/news17/28017.html">武汉服务器托管怎么选择地址</a> </li><li> <a class="text_overflow" href="/qtweb/news47/25297.html">怎么设置蓝牙耳机?(怎么设置蓝牙耳机按键功能)</a> </li><li> <a class="text_overflow" href="/qtweb/news8/6758.html">dns主机名称怎么设置</a> </li><li> <a class="text_overflow" href="/qtweb/news45/9395.html">服务器温度计指示灯:保障服务器运行稳定的必备工具(服务器温度计指示灯)</a> </li><li> <a class="text_overflow" href="/qtweb/news5/36955.html">Linux自启动目录指南:轻松设置开机自启程序(linux自启动目录)</a> </li><li> <a class="text_overflow" href="/qtweb/news11/23211.html">电脑Win10系统无法登陆,如何登陆?windows10的百度打不开怎么办</a> </li><li> <a class="text_overflow" href="/qtweb/news1/31201.html">学习项目管理之管理人的艺术</a> </li><li> <a class="text_overflow" href="/qtweb/news3/17703.html">巴西是什么服务器</a> </li><li> <a class="text_overflow" href="/qtweb/news42/33842.html">内容Linux下强制保存命令行内容的简易指南(linux强制保存命令行)</a> </li><li> <a class="text_overflow" href="/qtweb/news22/172.html">视频怎么添加文字?(视频怎么添加文字上去)</a> </li><li> <a class="text_overflow" href="/qtweb/news22/36922.html">一日一技:在Python里面如何实现一个抽象类</a> </li><li> <a class="text_overflow" href="/qtweb/news42/3192.html">租用美国服务器时需要考虑哪几个方面问题呢</a> </li><li> <a class="text_overflow" href="/qtweb/news15/18965.html">mac如何连接云主机设备</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/tongdiaosu/" 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/bolimo/" 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/ggsj/" 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/shachuang/" 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/chayisj/" 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/opp/" target="_blank">OPP胶袋</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/gangting/" 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/blgds/" 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/yupeng/" 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/chunshuiji/" 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/menchuang/" 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/xiaojbc/" 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/tadiaozulin/" 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/gaokongche/" 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/pe/" target="_blank">PE包装袋</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/bpfhw/" target="_blank">边坡防护网</a> </li> </ul> </div> </div> </div> <div class="carousel-inner linkbg" style="background: #fff"> <div class="container"> <a href="https://www.cdxwcx.com/wangzhan/mbqiye.html" target="_blank">成都企业网站制作</a>    <a href="http://www.cxjianzhan.com/" target="_blank">网站制作</a>    <a href="http://www.cdhuace.com/zhangui.html" target="_blank">成都展柜厂</a>    <a href="http://www.cxhljz.cn/" target="_blank">成都网站设计</a>    <a href="http://seo.cdcxhl.cn/" target="_blank">网站排名</a>    <a href="https://www.cdcxhl.com/xiyun.html" target="_blank">西云服务器托管</a>    <a href="http://www.cdxwcx.cn/tuoguan/yaan.html" target="_blank">雅安电信机房</a>    <a href="https://www.cdcxhl.com/mobile.html" target="_blank">手机网站制作设计</a>    <a href="http://www.cxhljz.com/" target="_blank">成都做网站建设公司</a>    <a href="http://www.scyanting.com/" target="_blank">四川盐亭做网站</a>    <a href="http://www.cdhuace.com/huace.html" target="_blank">成都画册制作</a>    <a href="http://www.cdxwcx.cn/sheji/" target="_blank">企业网站设计</a>    <a href="http://www.cdxwcx.cn/tuoguan/deyang.html" target="_blank">德阳机房托管</a>    <a href="https://www.cdcxhl.cn/ " target="_blank">免备案虚拟主机空间</a>    <a href="https://www.cdxwcx.com/wangzhan/app.html" target="_blank">app软件开发</a>    <a href="http://www.hikvision-dg.com/" target="_blank">卡多尼人工智</a>    <a href="https://www.cdxwcx.com/" target="_blank">成都网站建设</a>    <a href="http://www.xhgfhy.com/" target="_blank">犀浦防纹窗</a>    <a href="http://www.xhgfhy.com/ " target="_blank">犀浦防护栏定制</a>    <a href="https://www.scvps.cn/" 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> 节约开发成本 <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'"> 立即开始2800定制网站建设</button> <button type="button" class="btn btn-default btn-xs" onClick="window.location.href='tencent://message/?uin=631063699&Site=&Menu=yes'"> 2800定制网站建设</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.36103.cn/" target="_blank">成都网站设计</a> <a href="http://www.36103.cn/" target="_blank">成都网站制作</a> <a href="http://www.36103.cn/" 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:400-028-6601(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>