`
boogie
  • 浏览: 234755 次
  • 性别: Icon_minigender_1
  • 来自: 宁波
社区版块
存档分类
最新评论

在eXtremeComponents组件里实现列的动态显示

阅读更多
    在我开发的一个通用查询项目中想把查询结果集的显示部分采用eXtremeComponents组件来处理,但是碰到个问题,就是组件预先并不知道查询结果的列名,也就是必须解决Column列的动态显示问题。

    有一种方法就是通过在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>
分享到:
评论
8 楼 boogie 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那一快,写的很清楚!
7 楼 lformat 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.
6 楼 fins 2007-02-01  
ec里没有这段代码吧?你的ec是什么版本??1.01里没有啊
ecside里也没有
5 楼 lformat 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、除了这两个还有什么属性?
4 楼 Cecily 2007-01-18  
很不错呢,支持你奥
3 楼 boogie 2007-01-18  
fins 写道
哈哈 真高兴看到有关于ec的帖子
谢谢楼主
我的下一步改造计划中就包括对 AutoGenerateColumns 的争强
在AutoGenerateColumns接口的方法addColumns实现里,怎样实现根据查询得到的列值类型(日期型、数值型等)动态设置相关的显示格式?
正在研究中。。。,有解决方法还望回复,同时也可考虑增加到你的下一步改造计划中!
2 楼 fins 2007-01-17  
哈哈 真高兴看到有关于ec的帖子
谢谢楼主
我的下一步改造计划中就包括对 AutoGenerateColumns 的争强
1 楼 boogie 2007-01-17  
自己先顶一个,因为从博客文章导到论坛的时间有问题,应该是初次导入的时间而非博客编写时间

相关推荐

    eXtremeComponents组件

    "eXtremeComponents组件"是一组用于软件开发的组件,尤其在创建高效、功能丰富的用户界面时,这些组件能够极大地提升开发效率和用户体验。eXtremeComponents通常包括一系列的列表控件和其他UI元素,它们设计精良,...

    分页组件extremeComponents的使用

    5. **绑定数据**:将查询结果绑定到分页组件,显示在界面上。 6. **处理用户交互**:监听分页组件的事件,如页码变化,更新查询条件,重新执行查询并更新界面。 总之,Extreme Components的分页组件为Java Web开发...

    eXtremeComponents详尽文档包

    此文档可能会讨论表格的列定义、排序、过滤、分页等功能,以及如何处理数据模型和事件监听器,以实现动态数据更新和用户交互。 4. **EC标签总结.pdf** 标签可能是指EC中的标签组件或者其他与标记和分类相关的功能...

    eXtremeComponents详解

    XTable支持动态加载、分页、排序、过滤等功能,并且可以自定义列渲染,以满足各种数据展示需求。 2. **XPagingNavigator**: 为XTable提供分页导航,使得用户可以轻松浏览大量数据。 3. **XExport**: 提供数据导出...

    eXtremeComponents

    **TableTag** 是 eXtremeComponents 中的核心组件之一,用于生成和管理表格。 ##### 3.1 Introduction - **用途**: TableTag 用于构建具有高度自定义能力的表格。 - **特点**: 支持动态数据绑定、排序、过滤等功能...

    eXtremeComponents-1.0.1+中文API___分页工具

    在压缩包文件“eXtremeComponents-1.0.1-with-dependencies”中,包含的不仅是分页组件本身,还有其依赖的库文件。这意味着开发者可以立即开始使用,而无需额外寻找和配置相关的依赖项。这个压缩包确保了开发环境的...

    eXtremeComponents控件分页导出数据Demo.rar

    除了基础功能外,eXtremeComponents控件还提供了许多高级特性,如自定义分页样式、动态加载、多级分页等,可以根据项目需求进行选择和配置。在实际应用中,开发者还需要关注性能优化,比如使用虚拟化技术减少内存...

    eXtremeComponents学习总结

    核心组件eXtremeTable用于以表格形式展示数据,适用于需要动态、高效展示大量信息的Web应用程序。在使用ec之前,确保系统环境满足以下要求:JDK版本至少1.3,Servlet容器需支持2.3或更高版本。 eXtremeTable通过...

    ECSide文档.pdf

    ECSide,全称为Extreme Components Side,是一个开源的JSP列表组件,源于eXtremeComponents项目,但已独立发展并拥有自己的特色。这个组件专注于提供列表的显示功能,同时支持单表操作,如增、删、改、查。ECSide以...

    struts中ec标签的使用

    - `rowsDisplayed`属性定义了每页显示的行数,也可在`extremecomponents.properties`配置文件中全局设置。 - `showPagination`如果设为`false`,则表格不会分页显示所有数据。 - 样式属性如`cellspacing`, `...

Global site tag (gtag.js) - Google Analytics