浏览 10156 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-01-17
有一种方法就是通过在jsp页面里罗列一下,但是总感觉不舒服,查文档发现eXtremeComponents有一接口AutoGenerateColumns可实现此功能,以下为具体实现步骤: 一、在应用的servlet(或struts action等)里(如sqlAction.do)实现根据SQL语句的运行结果获取字段名称列表(fieldnames)和查询结果集(results)并将其放入httpRequest的属性中 List fieldnames = 实现[获取字段名称列表]方法; List results = 实现[获取查询结果集]方法; httpRequest.setAttribute("fieldnames", fieldnames); httpRequest.setAttribute("results", results); results将作为eXtremeTable组件中属性items的值,fieldnames将用来迭代构造Column对象 二、编写类AutoGenerateColumnsImpl实现org.extremecomponents.table.core.AutoGenerateColumns接口 package org.boogie.sql.common.ec; import java.util.Iterator; import java.util.List; import org.extremecomponents.table.bean.Column; import org.extremecomponents.table.core.AutoGenerateColumns; import org.extremecomponents.table.core.TableModel; public class AutoGenerateColumnsImpl implements AutoGenerateColumns { public void addColumns(TableModel model) { List fieldnames = (List) model.getContext().getRequestAttribute( "fieldnames"); Iterator iterator = fieldnames.iterator(); while (iterator.hasNext()) { String fieldname = (String) iterator.next(); Column column = model.getColumnInstance(); column.setProperty(fieldname); // column.setCell((String) columnToAdd.get(CELL)); model.getColumnHandler().addAutoGenerateColumn(column); } } } AutoGenerateColumns接口只有一个方法addColumns供实现,在此方法中通过传入的TableModel型参数model可从其Context中获取到httpRequest中的fieldnames属性值,然后根据fieldnames列表迭代构造对应Column后添加到model中 三、在显示页文件的eXtremeTable中,配置TableTag的属性items值为results,配置ColumnTag的属性autoGenerateColumns值为类AutoGenerateColumnsImpl的全路径 <ec:table items="results" var="result" action="${pageContext.request.contextPath}/sqlAction.do" imagePath="${pageContext.request.contextPath}/images/table/*.gif" title="查询结果" width="100%" rowsDisplayed="5" > <ec:parameter name="method" value="ec"/> <ec:row> <ec:columns autoGenerateColumns="org.boogie.sql.common.ec.AutoGenerateColumnsImpl"/> </ec:row> </ec:table> 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-01-17
自己先顶一个,因为从博客文章导到论坛的时间有问题,应该是初次导入的时间而非博客编写时间
|
|
返回顶楼 | |
发表时间:2007-01-17
哈哈 真高兴看到有关于ec的帖子
谢谢楼主 我的下一步改造计划中就包括对 AutoGenerateColumns 的争强 |
|
返回顶楼 | |
发表时间:2007-01-18
fins 写道 哈哈 真高兴看到有关于ec的帖子
在AutoGenerateColumns接口的方法addColumns实现里,怎样实现根据查询得到的列值类型(日期型、数值型等)动态设置相关的显示格式?谢谢楼主 我的下一步改造计划中就包括对 AutoGenerateColumns 的争强 正在研究中。。。,有解决方法还望回复,同时也可考虑增加到你的下一步改造计划中! |
|
返回顶楼 | |
发表时间:2007-01-18
很不错呢,支持你奥
|
|
返回顶楼 | |
发表时间:2007-01-31
private List columnsToAdd() { List columns = new ArrayList(); columns.add(columnToAdd("fullName", "display")); columns.add(columnToAdd("nickName", "display")); columns.add(columnToAdd("term", "display")); columns.add(columnToAdd("born", "date")); columns.add(columnToAdd("died", "date")); columns.add(columnToAdd("career", "display")); return columns; } 看到手册上这样写, 1、我想知道date是代表日期吗?那display代表什么? 2、除了这两个还有什么属性? |
|
返回顶楼 | |
发表时间:2007-02-01
ec里没有这段代码吧?你的ec是什么版本??1.01里没有啊
ecside里也没有 |
|
返回顶楼 | |
发表时间:2007-02-01
fins 写道 ec里没有这段代码吧?你的ec是什么版本??1.01里没有啊
ecside里也没有 是extremesite里的org.extremesite.controller.AutoGenerateColumnsImpl类 ec的手册上也有。 13.1. Introduction Most of the time when you design a table you will know exactly what columns you will need. However, there are times when it is nice to just generate the columns at runtime. To do this with eXtremeTable you will need to use the ColumnsTag and set the autoGenerateColumns attribute. The AutoGenerateColumns is now a singleton and is no longer thread safe so do not define any class variables. 13.2. ColumnsTag The ColumnsTag only has one attribute, autoGenerateColumns. The autoGenerateColumns attribute is the fully qualified path to the class that Implements the AutoGenerateColumns Interface, which is where all the custom work is done. <ec:table items="presidents" action="${pageContext.request.contextPath}/autoGenerateColumns.run" title="Presidents" > <ec:columns autoGenerateColumns="org.extremesite.controller.AutoGenerateColumnsImpl"/> </ec:table> The AutoGenerateColumns Interface only has one method: public void addColumns(TableModel model); What you are required to do is add the columns to the model. The easiest thing to do is show you an example: public class AutoGenerateColumnsImpl implements AutoGenerateColumns { public void addColumns(TableModel model) { Iterator iterator = columnsToAdd().iterator(); while (iterator.hasNext()) { Map columnToAdd = (Map) iterator.next(); Column column = new Column(model); column.setProperty((String) columnToAdd.get(PROPERTY)); column.setCell((String) columnToAdd.get(CELL)); model.getColumnHandler().addAutoGenerateColumn(column); } } } The columnsToAdd() method (in this example) simply returns a Collection that contains all the information to build the columns. I will leave it up to you on what that Collection looks like. As a reference here is what I used for the example on the eXtremeComponents site: private List columnsToAdd() { List columns = new ArrayList(); columns.add(columnToAdd("fullName", "display")); columns.add(columnToAdd("nickName", "display")); columns.add(columnToAdd("term", "display")); columns.add(columnToAdd("born", "date")); columns.add(columnToAdd("died", "date")); columns.add(columnToAdd("career", "display")); return columns; } eXtremeComponents Version 1.0.0 35 private Map columnToAdd(String property, String cell) { Map column = new HashMap(); column.put(Column.PROPERTY, property); column.put(Column.CELL, cell); return column; } One thing I wanted to add is that you are only creating a Column once. The eXtremeTable is very efficient and does not create a new Column for each row. Instead it just keeps inserting the new column value into the existing Column with each iteration over the tag. Also remember that the TableModel has access to the Context so you could build what the columns look like in a Controller (if using Spring) or an Action (if using Struts) and pass the Collection through the request. Then your AutoGenerateColumns implementation just needs to build the Columns and add them to the model. |
|
返回顶楼 | |
发表时间:2007-02-01
lformat 写道 private List columnsToAdd() { List columns = new ArrayList(); columns.add(columnToAdd("fullName", "display")); columns.add(columnToAdd("nickName", "display")); columns.add(columnToAdd("term", "display")); columns.add(columnToAdd("born", "date")); columns.add(columnToAdd("died", "date")); columns.add(columnToAdd("career", "display")); return columns; } 看到手册上这样写, 1、我想知道date是代表日期吗?那display代表什么? 2、除了这两个还有什么属性? 请看手册ColumnTag那一快,写的很清楚! |
|
返回顶楼 | |