jsf实现翻页

用jsf实现了翻页功能,主要原理是扩展datamodel和datatabletag
1 扩展datatabletag,增加了几个属性,用于后台执行查询语句
java 代码
 
  1. package com.longtop.core.web.jsf.tag;  
  2.   
  3. import javax.faces.application.Application;  
  4. import javax.faces.component.UIComponent;  
  5. import javax.faces.context.FacesContext;  
  6. import javax.faces.el.ValueBinding;  
  7.   
  8. import com.sun.faces.taglib.html_basic.DataTableTag;  
  9.   
  10. public class DataTableWithScrollTag extends DataTableTag {  
  11.     private boolean scroll = true;  
  12.   
  13.     private int pageSize = 10;  
  14.   
  15.     private String scrollPageCss = "";  
  16.     private String moduleId;  
  17.     private String statementId;  
  18.     private String beanName;  
  19.     private String implType;  
  20.     private String searchCondition;  
  21.      
  22.     /** 
  23.      * @return the pageSize 
  24.      */  
  25.     public int getPageSize() {  
  26.         return pageSize;  
  27.     }  
  28.   
  29.     /** 
  30.      * @param pageSize 
  31.      *            the pageSize to set 
  32.      */  
  33.     public void setPageSize(int pageSize) {  
  34.         this.pageSize = pageSize;  
  35.     }  
  36.   
  37.     /** 
  38.      * @return the scroll 
  39.      */  
  40.     public boolean isScroll() {  
  41.         return scroll;  
  42.     }  
  43.   
  44.     /** 
  45.      * @param scroll 
  46.      *            the scroll to set 
  47.      */  
  48.     public void setScroll(boolean scroll) {  
  49.         this.scroll = scroll;  
  50.     }  
  51.   
  52.     public String getComponentType() {  
  53.          
  54.         return "com.longtop.core.web.jsf.render.DataTableWithScrollType";  
  55.     }  
  56.   
  57.      
  58.     public void setProperties(UIComponent component) {  
  59.         super.setProperties(component);  
  60.         setStringProperty(component, "pageSize", String.valueOf(pageSize));  
  61.         setStringProperty(component, "scroll", String.valueOf(scroll));  
  62.         setStringProperty(component, "scrollPageCss", scrollPageCss);  
  63.         setStringProperty(component, "moduleId", moduleId);  
  64.         setStringProperty(component, "statementId", statementId);  
  65.         setStringProperty(component, "beanName", beanName);  
  66.         setStringProperty(component, "implType", implType);  
  67.         setStringProperty(component, "searchCondition", searchCondition);  
  68.     }  
  69.   
  70.     private void setStringProperty(UIComponent component, String attrName,  
  71.             String attrValue) {  
  72.         if (attrValue == null)  
  73.             return;  
  74.   
  75.         if (isValueReference(attrValue)) {  
  76.             FacesContext context = FacesContext.getCurrentInstance();  
  77.             Application application = context.getApplication();  
  78.             ValueBinding binding = application.createValueBinding(attrValue);  
  79.             component.setValueBinding(attrName, binding);  
  80.         } else {  
  81.             component.getAttributes().put(attrName, attrValue);  
  82.         }  
  83.     }  
  84.   
  85.     /** 
  86.      * @return the scrollPageCss 
  87.      */  
  88.     public String getScrollPageCss() {  
  89.         return scrollPageCss;  
  90.     }  
  91.   
  92.     /** 
  93.      * @param scrollPageCss the scrollPageCss to set 
  94.      */  
  95.     public void setScrollPageCss(String scrollPageCss) {  
  96.         this.scrollPageCss = scrollPageCss;  
  97.     }  
  98.   
  99.     /** 
  100.      * @return the moduleId 
  101.      */  
  102.     public String getModuleId() {  
  103.         return moduleId;  
  104.     }  
  105.   
  106.     /** 
  107.      * @param moduleId the moduleId to set 
  108.      */  
  109.     public void setModuleId(String moduleId) {  
  110.         this.moduleId = moduleId;  
  111.     }  
  112.   
  113.     /** 
  114.      * @return the statementId 
  115.      */  
  116.     public String getStatementId() {  
  117.         return statementId;  
  118.     }  
  119.   
  120.     /** 
  121.      * @param statementId the statementId to set 
  122.      */  
  123.     public void setStatementId(String statementId) {  
  124.         this.statementId = statementId;  
  125.     }  
  126.   
  127.     /** 
  128.      * @return the beanName 
  129.      */  
  130.     public String getBeanName() {  
  131.         return beanName;  
  132.     }  
  133.   
  134.     /** 
  135.      * @param beanName the beanName to set 
  136.      */  
  137.     public void setBeanName(String beanName) {  
  138.         this.beanName = beanName;  
  139.     }  
  140.   
  141.     /** 
  142.      * @return the implType 
  143.      */  
  144.     public String getImplType() {  
  145.         return implType;  
  146.     }  
  147.   
  148.     /** 
  149.      * @param implType the implType to set 
  150.      */  
  151.     public void setImplType(String implType) {  
  152.         this.implType = implType;  
  153.     }  
  154.   
  155.     /** 
  156.      * @return the searchCondition 
  157.      */  
  158.     public String getSearchCondition() {  
  159.         return searchCondition;  
  160.     }  
  161.   
  162.     /** 
  163.      * @param searchCondition the searchCondition to set 
  164.      */  
  165.     public void setSearchCondition(String searchCondition) {  
  166.         this.searchCondition = searchCondition;  
  167.     }  
  168.   
  169. }  

2 dragon.tld
xml 代码
 
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE taglib  
  3. PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"  
  4. "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">  
  5. <taglib>  
  6.     <tlib-version>1.0</tlib-version>  
  7.     <jsp-version>2.0</jsp-version>  
  8.     <short-name>d</short-name>  
  9.     <uri>http://com.longtop.net/dataTableWithScroll</uri>  
  10.     <tag>  
  11.         <name>scrollDataTable</name>  
  12.         <tag-class>com.longtop.core.web.jsf.tag.DataTableWithScrollTag</tag-class>  
  13.         <tei-class>com.sun.faces.taglib.FacesTagExtraInfo</tei-class>  
  14.     <body-content>JSP</body-content>  
  15.     <description>  
  16.         
  17.     </description>  
  18.     <attribute>  
  19.       <name>first</name>  
  20.       <required>false</required>  
  21.       <rtexprvalue>false</rtexprvalue>  
  22.       <description>  
  23.         
  24.           Zero-relative row number of the first row to be displayed.  If this  
  25.           property is set to zero, rendering will begin with the first row of  
  26.           the underlying data.  
  27.       </description>  
  28.     </attribute>  
  29.     <attribute>  
  30.       <name>id</name>  
  31.       <required>false</required>  
  32.       <rtexprvalue>false</rtexprvalue>  
  33.       <description>  
  34.         
  35.           The component identifier for this component.  This value must be  
  36.           unique within the closest parent component that is a naming  
  37.           container.  
  38.       </description>  
  39.     </attribute>  
  40.     <attribute>  
  41.       <name>rendered</name>  
  42.       <required>false</required>  
  43.       <rtexprvalue>false</rtexprvalue>  
  44.       <description>  
  45.         
  46.           Flag indicating whether or not this component should be rendered  
  47.           (during Render Response Phase), or processed on any subsequent  
  48.           form submit.  
  49.       </description>  
  50.     </attribute>  
  51.     <attribute>  
  52.       <name>rows</name>  
  53.       <required>false</required>  
  54.       <rtexprvalue>false</rtexprvalue>  
  55.       <description>  
  56.         
  57.           The number of rows to display, starting with the one identified by the  
  58.           "first" property.  If this value is set to zero, all available rows in  
  59.           the underlying data model will be displayed.  
  60.       </description>  
  61.     </attribute>  
  62.     <attribute>  
  63.       <name>value</name>  
  64.       <required>false</required>  
  65.       <rtexprvalue>false</rtexprvalue>  
  66.       <description>  
  67.         
  68.           The current value of this component.  
  69.       </description>  
  70.     </attribute>  
  71.     <attribute>  
  72.       <name>var</name>  
  73.       <required>false</required>  
  74.       <rtexprvalue>false</rtexprvalue>  
  75.       <description>  
  76.         
  77.           Name of a request-scope attribute under which the model data for the  
  78.           row selected by the current value of the "rowIndex" property (i.e.  
  79.           also the current value of the "rowData" property) will be exposed.  
  80.       </description>  
  81.     </attribute>  
  82.     <attribute>  
  83.       <name>bgcolor</name>  
  84.       <required>false</required>  
  85.       <rtexprvalue>false</rtexprvalue>  
  86.       <description>  
  87.         
  88.           Name or code of the background color for this table.  
  89.       </description>  
  90.     </attribute>  
  91.     <attribute>  
  92.       <name>border</name>  
  93.       <required>false</required>  
  94.       <rtexprvalue>false</rtexprvalue>  
  95.       <description>  
  96.         
  97.           Width (in pixels) of the border to be drawn  
  98.           around this table.  
  99.       </description>  
  100.     </attribute>  
  101.     <attribute>  
  102.       <name>cellpadding</name>  
  103.       <required>false</required>  
  104.       <rtexprvalue>false</rtexprvalue>  
  105.       <description>  
  106.         
  107.           Definition of how much space the user agent should  
  108.           leave between the border of each cell and its contents.  
  109.       </description>  
  110.     </attribute>  
  111.     <attribute>  
  112.       <name>cellspacing</name>  
  113.       <required>false</required>  
  114.       <rtexprvalue>false</rtexprvalue>  
  115.       <description>  
  116.         
  117.           Definition of how much space the user agent should  
  118.           leave between the left side of the table and the  
  119.           leftmost column, the top of the table and the top of  
  120.           the top side of the topmost row, and so on for the  
  121.           right and bottom of the table.  It also specifies  
  122.           the amount of space to leave between cells.  
  123.       </description>  
  124.     </attribute>  
  125.     <attribute>  
  126.       <name>columnClasses</name>  
  127.       <required>false</required>  
  128.       <rtexprvalue>false</rtexprvalue>  
  129.       <description>  
  130.         
  131.           Comma-delimited list of CSS style classes that will be applied  
  132.           to the columns of this table.  A space separated list of  
  133.           classes may also be specified for any individual column.  If  
  134.           the number of elements in this list is less than the number of  
  135.           columns specified in the "columns" attribute, no "class"  
  136.           attribute is output for each column greater than the number of  
  137.           elements in the list.  If the number of elements in the list  
  138.           is greater than the number of columns specified in the  
  139.           "columns" attribute, the elements at the posisiton in the list  
  140.           after the value of the "columns" attribute are ignored.  
  141.       </description>  
  142.     </attribute>  
  143.     <attribute>  
  144.       <name>dir</name>  
  145.       <required>false</required>  
  146.       <rtexprvalue>false</rtexprvalue>  
  147.       <description>  
  148.         
  149.           Direction indication for text that does not inherit directionality.  
  150.           Valid values are "LTR" (left-to-right) and "RTL" (right-to-left).  
  151.       </description>  
  152.     </attribute>  
  153.     <attribute>  
  154.       <name>footerClass</name>  
  155.       <required>false</required>  
  156.       <rtexprvalue>false</rtexprvalue>  
  157.       <description>  
  158.         
  159.           Space-separated list of CSS style class(es) that will be  
  160.           applied to any footer generated for this table.  
  161.       </description>  
  162.     </attribute>  
  163.     <attribute>  
  164.       <name>frame</name>  
  165.       <required>false</required>  
  166.       <rtexprvalue>false</rtexprvalue>  
  167.       <description>  
  168.         
  169.           Code specifying which sides of the frame surrounding  
  170.           this table will be visible.  Valid values are:  
  171.           none (no sides, default value); above (top side only);  
  172.           below (bottom side only); hsides (top and bottom sides  
  173.           only); vsides (right and left sides only); lhs (left  
  174.           hand side only); rhs (right hand side only); box  
  175.           (all four sides); and border (all four sides).  
  176.       </description>  
  177.     </attribute>  
  178.     <attribute>  
  179.       <name>headerClass</name>  
  180.       <required>false</required>  
  181.       <rtexprvalue>false</rtexprvalue>  
  182.       <description>  
  183.         
  184.           Space-separated list of CSS style class(es) that will be  
  185.           applied to any header generated for this table.  
  186.       </description>  
  187.     </attribute>  
  188.     <attribute>  
  189.       <name>lang</name>  
  190.       <required>false</required>  
  191.       <rtexprvalue>false</
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值