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.shufengxianlan.com/qtweb/news1/185701.html">JSF动态生成固定表头和行标的DataTable</a> <br> 本文地址:<a href="http://www.shufengxianlan.com/qtweb/news1/185701.html">http://www.shufengxianlan.com/qtweb/news1/185701.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/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/appsheji/">App设计知识</a></p> <ul> <li> <a class="text_overflow" href="/qtweb/news31/333781.html">深度探索Linux系统CPU使用情况(linux查看cpu使用情况)</a> </li><li> <a class="text_overflow" href="/qtweb/news14/10214.html">开发一个小程序,需要先买服务器和域名么?传统服务器有必要购买域名吗</a> </li><li> <a class="text_overflow" href="/qtweb/news37/109487.html">个人企业邮箱注册申请,outlook企业邮箱注册申请不了</a> </li><li> <a class="text_overflow" href="/qtweb/news11/230261.html">香港服务器和美国服务器哪个好?香港的服务器用哪个好</a> </li><li> <a class="text_overflow" href="/qtweb/news20/256320.html">云服务器如何二次虚拟化?(云服务器如何虚拟化)</a> </li><li> <a class="text_overflow" href="/qtweb/news25/434675.html">win10如何远程锁定硬盘?(windows远程获取磁盘)</a> </li><li> <a class="text_overflow" href="/qtweb/news2/347352.html">Linux系统下查询当前系统时间(获取linux当前时间)</a> </li><li> <a class="text_overflow" href="/qtweb/news28/545078.html">Python程序:检查数字是否是Harshad数字</a> </li><li> <a class="text_overflow" href="/qtweb/news18/505018.html">html中如何设置会动的标题</a> </li><li> <a class="text_overflow" href="/qtweb/news26/233826.html">keep的用法?(keepwindows)</a> </li><li> <a class="text_overflow" href="/qtweb/news10/86360.html">Linux系统中的FTP脚本实现简单快捷(ftp脚本linux)</a> </li><li> <a class="text_overflow" href="/qtweb/news35/30935.html">VR虚拟现实应用各个行业系列</a> </li><li> <a class="text_overflow" href="/qtweb/news29/357879.html">域名证书的作用是什么,什么是域名证书</a> </li><li> <a class="text_overflow" href="/qtweb/news10/145910.html">数据库选型要考虑哪些问题?</a> </li><li> <a class="text_overflow" href="/qtweb/news5/533505.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/led/" target="_blank">LED显示屏</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/shidiao/" 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/qchs/" 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/huisuosj/" 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/jiaquan/" 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/sdgz/" 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/hldzj/" 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/dibang/" 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/zsljbc/" 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/menlian/" 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/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/xiaojbc/" target="_blank">小搅拌车</a> </li> </ul> </div> </div> </div> <div class="carousel-inner linkbg" style="background: #fff"> <div class="container"> <a href="https://www.cdcxhl.com/shop.html" target="_blank">商城网站建设</a>    <a href="http://www.scfushun.com/" target="_blank">富顺网站建设</a>    <a href="https://www.cdcxhl.com/mianfei/jianzhan/chengdu.html" target="_blank">成都免费建站</a>    <a href="http://www.yfrsc.cn/" target="_blank">成都圣月制冷</a>    <a href="http://www.cdkjz.cn/fangan/finance/" target="_blank">金融行业网站建设方案</a>    <a href="http://www.cdxwcx.cn/tuoguan/sichuan.html" target="_blank">四川服务器托管</a>    <a href="https://www.cdxwcx.com/" target="_blank">成都网站制作</a>    <a href="http://m.xwcx.net/wechat/" target="_blank">成都微信二次开发</a>    <a href="http://www.cxhlcq.com/seo/" target="_blank">重庆网络营销</a>    <a href="http://m.cdcxhl.cn/dingzhi/" target="_blank">成都定制网站建设</a>    <a href="http://www.cdhuace.com/" target="_blank">成都广告公司</a>    <a href="http://www.swwzsj.com/" target="_blank">汕尾凯敏网站</a>    <a href="http://www.cdkjz.cn/wangzhan/keyseo/" target="_blank">成都关键词SEO优化</a>    <a href="https://www.scvps.cn/" target="_blank">租用服务器</a>    <a href="https://www.xwcx.net/zuyong.html" target="_blank">服务器租用</a>    <a href="http://www.jinhuajc.com/" target="_blank">橡塑保温管</a>    <a href="http://www.kswsj.cn/" target="_blank">成都网站建设</a>    <a href="http://www.cdxwcx.cn/tuoguan/deyang.html" target="_blank">德阳电信服务器托管</a>    <a href="http://www.jinhuajc.com/" target="_blank">成都保温材料</a>    <a href="http://www.75091.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="https://www.cdcxhl.com/" target="_blank">网站设计</a> <a href="https://www.cdcxhl.com/" target="_blank">网站制作</a> <a href="https://www.cdcxhl.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: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>