网站公告列表

  没有公告

加入收藏
设为首页
联系站长
您现在的位置: 网络学院 >> 程序设计 >> Java编程 >> 文章正文
  eXtremeComponents的eXtremeTable分页特性            【字体:
eXtremeComponents的eXtremeTable分页特性
作者:佚名    文章来源:不详    点击数:    更新时间:2007-9-2    

eXtremeComponents的eXtremeTable是一套很好的分页标签,比displayTag好多了。
正在装载数据……
它使用jstl,所以与webwork,Struts,JSF 集成也很方便,推荐大家用


下面是我使用的例子:


<ec:table items="users" var="user" action="" imagePath="${ctx}/widgets/extremecomponents/images/table/zh_CN/*.gif" cellpadding="1" title="用户名" 
 locale
="zh_CN" rowsDisplayed="10"> 
     
<ec:exportXls fileName="UserList.xls" tooltip="Export Excel"/>
     
<ec:exportPdf fileName="UserList.pdf" tooltip="输出PDF文件" headerColor="blue" headerBackgroundColor="blue" headerTitle="人员表"/> 
   
<ec:exportCsv fileName="UserList.txt" tooltip="输出CSV文件" delimiter="|"/> 

   
<ec:row>
    
<ec:column property="rowcount" cell="rowCount" sortable="false" title=" No." width="50"/>
    
<ec:column property="username" title="姓 名" width="200"/>
    
<ec:column property="firstName"  title="firstName" width="200"/>
    
<ec:column property="lastName"  title="lastName" width="200"/>
   
</ec:row>
  
</ec:table>

Action

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.ygsoft.propertyright.service.UserManager;
import com.ygsoft.propertyright.webapp.util.BeanUtil;

public class TestAction extends BaseAction {
    UserManager userManager 
= (UserManager)BeanUtil.getBean("userManager");
    
    
public ActionForward testPage(ActionMapping mapping, ActionForm form, 
            HttpServletRequest request, HttpServletResponse response) 
throws Exception {
        List users 
= getUsers();
        request.setAttribute(
"users", users);
        
return mapping.findForward("test");
    }


    
public List getUsers() throws Exception {
                 
return userManager.getUsers(null);    
                     }

}

              其中ecoAttrs是一个collection(List),放入pojo。action里面写你这个页面的访问方法(如我的页面是一个action,其他的如.do或者.jsp什么的都可以)。rowsDisplayed是默认显示条数,它可以自动实现分页。
下面的三个<ec:export>是导出三种格式用的,不用的话可以不写(写了需要在web.xml配置相应的filter)。
<ec:column>里面放属性,property指向pojo的相应属性,而title是表头显示的信息,这个标签需要用<ec:row>包起来(1.0.1 m4以后)

这里有一套中文图标:
http://tiny.51.net/extremecomponent/zh_CN.rar

web.xml配置

<filter> 
     
<filter-name>eXtremeExport</filter-name> 
    
<filter-class> org.extremecomponents.table.filter.ExportFilter </filter-class> 
</filter> 

<!-- 输出excel,pdf,csv的时候用 -->
<filter-mapping> 
<filter-name>eXtremeExport</filter-name> 
<url-pattern>/*</url-pattern> 
</filter-mapping> 


<!-- 其实这个配置可不要,已经在放在jar里面了loading的时候自动会加进来- -->
<taglib> 
<taglib-uri>/extremecomponents</taglib-uri> 
<taglib-location>/WEB-INF/tld/extremecomponents.tld</taglib-location>
<!--tld拷贝到相应目录去-> 
</taglib> 

中文问题

export里面的excel和pdf默认不支持中文,需要手工修改源码,excel的比较简单:
修改org.extremecomponents.table.view.XlsView.java(我指的是1.0.1-M4-A14的相应代码)
102行:
HSSFCell hssfCell = hssfRow.createCell(cellnum);
hssfCell.setEncoding(HSSFCell.ENCODING_UTF_16);(就是添加这一行)
122行:
HSSFCell cell = row.createCell(cellnum);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);(就是添加这一行)
这个在使用UTF-8时工作正常。如果其他Unicode环境可以尝试HSSFCell.ENCODING_COMdivSSED_UNICODE。

编译后将对应.class放到WEB-INF/classes相应目录就可以了。

pdf view的比较麻烦,还没尝试,解决方法参照这个帖子:
http://extremecomponents.org/forum/viewtopic.php?t=139&highlight=chinese+filter
http://www-128.ibm.com/developerworks/cn/xml/x-ospdf/index.html

以使用Struts为例,说明一下如何使用eXtremeTable的分页特性

 

   这一切都可以在Action中完成,在Action会用到JSP中eXtremeTable的table标签的属性'tableId' 和'item','tableId'用于完成eXtremeTable的分页,'item'用于返回你分页的结果集,不多不少,刚好是你需要查看的那一页的结果集,比如说,你一页是10条记录,那你访问第20页的时候,'item'的结果集就只有第201条到第210条记录.还有就是在request中加入totalRows的属性,表示本次查询结果的数量

另外,JSP的中,eXtremeTable的table标签要retrieveRowsCallback属性,将该属性设为 org.extremecomponents.table.callback.LimitCallback,这是它默认的分页回调类,你也可以写自已的回调类.设置了该默认的回调类以后,你在Action里就需要向request加入totalRows属性,值为你的查询结果总记录数,这样才会产生翻页的效果.

现在就你的DisplayAction中加分页的特性了,如下:

Limit limit = LimitFactory.createInstanceOfLimit(request, TABLEID);
LimitFactory.setLimitPageAndRowAttr(limit,PAGE_SIZE,TOTAL_SIZE);

这里的TABLEID就是JSP页上标签的属性tableId, PAGE_SIZE是你一页的记录数,TOTAL_SIZE是你查询数据的总数

然后设置totalRow属性,它的值被要求为Integer类型的,转换一下:

request.setAttribute("totalRows",new Integer(TOTAL_SIZE));

将分页后的结果集(一页的内容)放到request的resultList(此为JSP中item属性设置的值)属性中去:

request.setAttribute("resultList", getTestData(limit.getCurrentRowsDisplayed(),limit.getPage()));

上面得到分页数据的函数原形为getTestData(int pageSize,int paget),通过指定一页的记录数和第几页来获得所需的数据,这可以根据数据库的分页特性,或者通过滑动游标的方式来得到,这里不再傲述.

以下为部分代码:

JSP部分:

<ec:table
 
items="resultList" var="item" tableId="youTableId"
        retrieveRowsCallback
="org.extremecomponents.table.callback.LimitCallback"
        filterRowsCallback
="org.extremecomponents.table.callback.LimitCallback"
        sortRowsCallback
="org.extremecomponents.table.callback.LimitCallback"
 action
="${pageContext.request.contextPath}/DisplayAction.do"
 imagePath
="${pageContext.request.contextPath}/images/table/*.gif"
 title
="TEST"
 width
="100%"
 rowsDisplayed
="10"
        sortable
="false"
        filterable
="false"
 
>
        
<ec:column property="name" title="姓名"/>
        
<ec:column property="nickName" title="别名"/>
</ec:table>

 

Action部分代码:

Limit limit = LimitFactory.createInstanceOfLimit(request, TABLEID);
LimitFactory.setLimitFilterAndSortAttr(limit);
LimitFactory.setLimitPageAndRowAttr(limit,PAGE_SIZE,TOTAL_SIZE);
request.setAttribute(
"resultList",getTestData(limit.getCurrentRowsDisplayed(),limit.getPage()));
request.setAttribute(
"totalRows",new Integer(TOTAL_SIZE));

,标签里的rowDisplayed属性要和Action中的PAGE_SIZE一致,不然会有问题...

其他资源
extremecomponents 用AJAX:
http://extremecomponents.org/wiki/index.php/AJAX_enabled_eXtremeTable_Tutorial
extremecomponents Group:
http://groups.google.com:80/group/eXtremeComponents_CN
资源
http://www.blogjava.net:80/lucky/category/7508.html
官方网站
http://www.extremecomponents.org





本文来源:http://blog.csdn.net/GOALSTAR/archive/2007/07/27/1711822.aspx
站内文章搜索 高级搜索
文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
     用java实现web服务器
     用java快速开发linux gu…
     正则表达式分解siemens交…
     [portal参考手册]目录
     jsp中调用oracle存储过程…
  • page、request、session、ap…

  • JSF 的性能远不及 JSP 或 St…

  • Core Java 之旅

  • Struts2学习:在struts2中集…

  • 浅析Spring框架下PropertyPl…

  • SPRING+STRUTS+HIBERNATE登录…

  • genexus中对字符串的格式补空…

  • struts多附件上传

  • jsp重定向forward和sendRedi…

  • struts异常_does not start …

  •   网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    网络学院©2007 www.23book.net
    为您提供web编程,vb编程,vc编程,服务器架设管理,数据库设计等方面的知识 站长:David