用jsf实现了翻页功能,主要原理是扩展datamodel和datatabletag
1 扩展datatabletag,增加了几个属性,用于后台执行查询语句
2 dragon.tld
1 扩展datatabletag,增加了几个属性,用于后台执行查询语句
java 代码
- package com.longtop.core.web.jsf.tag;
- import javax.faces.application.Application;
- import javax.faces.component.UIComponent;
- import javax.faces.context.FacesContext;
- import javax.faces.el.ValueBinding;
- import com.sun.faces.taglib.html_basic.DataTableTag;
- public class DataTableWithScrollTag extends DataTableTag {
- private boolean scroll = true;
- private int pageSize = 10;
- private String scrollPageCss = "";
- private String moduleId;
- private String statementId;
- private String beanName;
- private String implType;
- private String searchCondition;
- /**
- * @return the pageSize
- */
- public int getPageSize() {
- return pageSize;
- }
- /**
- * @param pageSize
- * the pageSize to set
- */
- public void setPageSize(int pageSize) {
- this.pageSize = pageSize;
- }
- /**
- * @return the scroll
- */
- public boolean isScroll() {
- return scroll;
- }
- /**
- * @param scroll
- * the scroll to set
- */
- public void setScroll(boolean scroll) {
- this.scroll = scroll;
- }
- public String getComponentType() {
- return "com.longtop.core.web.jsf.render.DataTableWithScrollType";
- }
- public void setProperties(UIComponent component) {
- super.setProperties(component);
- setStringProperty(component, "pageSize", String.valueOf(pageSize));
- setStringProperty(component, "scroll", String.valueOf(scroll));
- setStringProperty(component, "scrollPageCss", scrollPageCss);
- setStringProperty(component, "moduleId", moduleId);
- setStringProperty(component, "statementId", statementId);
- setStringProperty(component, "beanName", beanName);
- setStringProperty(component, "implType", implType);
- setStringProperty(component, "searchCondition", searchCondition);
- }
- private void setStringProperty(UIComponent component, String attrName,
- String attrValue) {
- if (attrValue == null)
- return;
- if (isValueReference(attrValue)) {
- FacesContext context = FacesContext.getCurrentInstance();
- Application application = context.getApplication();
- ValueBinding binding = application.createValueBinding(attrValue);
- component.setValueBinding(attrName, binding);
- } else {
- component.getAttributes().put(attrName, attrValue);
- }
- }
- /**
- * @return the scrollPageCss
- */
- public String getScrollPageCss() {
- return scrollPageCss;
- }
- /**
- * @param scrollPageCss the scrollPageCss to set
- */
- public void setScrollPageCss(String scrollPageCss) {
- this.scrollPageCss = scrollPageCss;
- }
- /**
- * @return the moduleId
- */
- public String getModuleId() {
- return moduleId;
- }
- /**
- * @param moduleId the moduleId to set
- */
- public void setModuleId(String moduleId) {
- this.moduleId = moduleId;
- }
- /**
- * @return the statementId
- */
- public String getStatementId() {
- return statementId;
- }
- /**
- * @param statementId the statementId to set
- */
- public void setStatementId(String statementId) {
- this.statementId = statementId;
- }
- /**
- * @return the beanName
- */
- public String getBeanName() {
- return beanName;
- }
- /**
- * @param beanName the beanName to set
- */
- public void setBeanName(String beanName) {
- this.beanName = beanName;
- }
- /**
- * @return the implType
- */
- public String getImplType() {
- return implType;
- }
- /**
- * @param implType the implType to set
- */
- public void setImplType(String implType) {
- this.implType = implType;
- }
- /**
- * @return the searchCondition
- */
- public String getSearchCondition() {
- return searchCondition;
- }
- /**
- * @param searchCondition the searchCondition to set
- */
- public void setSearchCondition(String searchCondition) {
- this.searchCondition = searchCondition;
- }
- }
2 dragon.tld
xml 代码
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE taglib
- PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
- "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
- <taglib>
- <tlib-version>1.0</tlib-version>
- <jsp-version>2.0</jsp-version>
- <short-name>d</short-name>
- <uri>http://com.longtop.net/dataTableWithScroll</uri>
- <tag>
- <name>scrollDataTable</name>
- <tag-class>com.longtop.core.web.jsf.tag.DataTableWithScrollTag</tag-class>
- <tei-class>com.sun.faces.taglib.FacesTagExtraInfo</tei-class>
- <body-content>JSP</body-content>
- <description>
- </description>
- <attribute>
- <name>first</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- <description>
- Zero-relative row number of the first row to be displayed. If this
- property is set to zero, rendering will begin with the first row of
- the underlying data.
- </description>
- </attribute>
- <attribute>
- <name>id</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- <description>
- The component identifier for this component. This value must be
- unique within the closest parent component that is a naming
- container.
- </description>
- </attribute>
- <attribute>
- <name>rendered</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- <description>
- Flag indicating whether or not this component should be rendered
- (during Render Response Phase), or processed on any subsequent
- form submit.
- </description>
- </attribute>
- <attribute>
- <name>rows</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- <description>
- The number of rows to display, starting with the one identified by the
- "first" property. If this value is set to zero, all available rows in
- the underlying data model will be displayed.
- </description>
- </attribute>
- <attribute>
- <name>value</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- <description>
- The current value of this component.
- </description>
- </attribute>
- <attribute>
- <name>var</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- <description>
- Name of a request-scope attribute under which the model data for the
- row selected by the current value of the "rowIndex" property (i.e.
- also the current value of the "rowData" property) will be exposed.
- </description>
- </attribute>
- <attribute>
- <name>bgcolor</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- <description>
- Name or code of the background color for this table.
- </description>
- </attribute>
- <attribute>
- <name>border</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- <description>
- Width (in pixels) of the border to be drawn
- around this table.
- </description>
- </attribute>
- <attribute>
- <name>cellpadding</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- <description>
- Definition of how much space the user agent should
- leave between the border of each cell and its contents.
- </description>
- </attribute>
- <attribute>
- <name>cellspacing</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- <description>
- Definition of how much space the user agent should
- leave between the left side of the table and the
- leftmost column, the top of the table and the top of
- the top side of the topmost row, and so on for the
- right and bottom of the table. It also specifies
- the amount of space to leave between cells.
- </description>
- </attribute>
- <attribute>
- <name>columnClasses</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- <description>
- Comma-delimited list of CSS style classes that will be applied
- to the columns of this table. A space separated list of
- classes may also be specified for any individual column. If
- the number of elements in this list is less than the number of
- columns specified in the "columns" attribute, no "class"
- attribute is output for each column greater than the number of
- elements in the list. If the number of elements in the list
- is greater than the number of columns specified in the
- "columns" attribute, the elements at the posisiton in the list
- after the value of the "columns" attribute are ignored.
- </description>
- </attribute>
- <attribute>
- <name>dir</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- <description>
- Direction indication for text that does not inherit directionality.
- Valid values are "LTR" (left-to-right) and "RTL" (right-to-left).
- </description>
- </attribute>
- <attribute>
- <name>footerClass</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- <description>
- Space-separated list of CSS style class(es) that will be
- applied to any footer generated for this table.
- </description>
- </attribute>
- <attribute>
- <name>frame</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- <description>
- Code specifying which sides of the frame surrounding
- this table will be visible. Valid values are:
- none (no sides, default value); above (top side only);
- below (bottom side only); hsides (top and bottom sides
- only); vsides (right and left sides only); lhs (left
- hand side only); rhs (right hand side only); box
- (all four sides); and border (all four sides).
- </description>
- </attribute>
- <attribute>
- <name>headerClass</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- <description>
- Space-separated list of CSS style class(es) that will be
- applied to any header generated for this table.
- </description>
- </attribute>
- <attribute>
- <name>lang</name>
- <required>false</required>
- <rtexprvalue>false</