博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

jUsT olD tiMe

-=编程 艺术 人生=-
  hello386.cublog.cn

关于作者
姓名:豆子
职业:程序员
年龄:属狗的
位置:北京
个性介绍:
|| << >> ||
我的分类


eXtremeComponents参考文档(2)

eXtremeComponents

参考文档

Jeff Johnston

版本1.0.0

本文档允许在遵守以下两条原则的条件下被使用和传播: 1)不能凭借本文档索取任何费用 2)以任何方式(印刷物或电子版)使用和传播时本文档时,必须包含本版权申明

Chapter 9. 视图

9.1. 引言

eXtremeTable里视图是可插接的,这意味着html很容易改变,或者一类新的导出能够被实现。 所有需要做的就是实现View接口并在TableTag或ExportTag中设置view属性。首先,让我们看一下View接口:

public interface View {
  public void beforeBody(TableModel model);
  public void body(TableModel model, Column column);
  public Object afterBody(TableModel model);
}

实现View接口的类有三次插入内容的机会。beforeBody()方法会被立刻调用; body()方法在每一行的每一列处理的时候调用;afterBody()方法是被eXtremeTable调用的 最后方法,它将返回代表视图的一个对象,通常它是一个字符串。例如:在HTML视图类中为的html 标签(markup),当然它可以是任何东西。最主要的原因是定制导出时,你应该返回一些其他的对象。

9.2. 表视图

eXtremeTable的所有标签(markup)在两个地方生成:View或Cell。 组合使用他们, 能为你提供一种可插接的表示内容的解决方案。为了使用定制的View, 只需要使用TableTag的view属性来指定实现View接口的实现类的 全路径:

<ec:table
  items="presidents"
  action="${pageContext.request.contextPath}/presidents.run"
  view="com.mycompany.view.MyCustomView"
  >
  ...
</ec:table>

9.3. 导出视图

与表视图不同,export的所有标签都在View中生成。为了使用定制的View, 只需要使用ExportTag的view属性来指定实现View接口的实现类的 全路径:

<ec:table
  items="presidents"
  action="${pageContext.request.contextPath}/presidents.run"
  >
  <ec:export
    fileName="custom.file"
    tooltip="Export Custom"
    view="com.mycompany.view.MyCustomExportView"/>
  ...
</ec:table>

Chapter 10. Preferences

10.1. 引言

为了替代硬编码eXtremeTable使用的默认属性值,我在属性文件中配置所有用到的属性。 如果你需要覆盖任何默认的设置,你可以创建自己的extremecomponents.properties文件 并设置你想改变的值。

为了设置属性文件,你应该如下例所示在/WEB-INF/web.xml文件中声明一个context-param,并 指定你的属性文件的路径:

<context-param>
  <param-name>extremecomponentsPreferencesLocation</param-name>
  <param-value>/org/extremesite/resource/extremecomponents.properties</param-value>
</context-param>

你可以认为属性文件为你提供了一个对所有的eXtremeTables声明全局设置的一个方法。 创建属性文件的最大好处就是避免在标签中复制、粘贴相同的属性。典型的extremecomponents.properties文件如下所示:

table.imagePath=/extremesite/images/*.gif
table.rowsDisplayed=12
column.parse.date=yyyy-MM-dd
column.format.date=MM/dd/yyyy
column.format.currency=$###,###,##0.00

10.2. TableTag

在属性文件定义的TableTag使用最多的两个属性是:imagePath和rowsDisplayed。如果你不在属性文件中声明 这些属性,你需要在每个eXtremeTable中添加他们。典型的表如下所示:

<ec:table
  items="presidents"
  action="${pageContext.request.contextPath}/presidents.run"
  imagePath="${pageContext.request.contextPath}/images/*.gif"
  rowsDisplayed="12"
  title="Presidents"
  >
  ...
</ec:table>

如果在属性文件声明imagePath和rowsDisplayed,则表如下所示:

<ec:table
  items="presidents"
  action="${pageContext.request.contextPath}/presidents.run"
  title="Presidents"
  >
  ...
</ec:table>

正如你所见,属性文件避免了重复编码。

10.3. ColumnTag

在属性文件定义的ColumnTag使用最多的两个属性是:parse和format。如果你不在属性文件中声明 这些属性,你需要在每个eXtremeTable中添加他们。典型的列使用日期cell如下所示:

<ec:column property="dateOfBirth" cell=”date” parse=”yyyy-MM-dd” format=”MM/dd/yyyy”/> 

如果在属性文件声明parse和format,则列如下所示:

<ec:column property="dateOfBirth" cell=”date”/> 

当然你仍然可以定义parse和format属性来覆盖全局设置,但是大多数工程对于日期使用一致的parse 和format。需要注意属性文件中parse.date和format.date的声明语法。

下例为使用货币cell的典型列:

<ec:column property="salary" cell=”currency” format=”$###,###,##0.00”/> 

如果在属性文件声明format,则列如下所示:

<ec:column property="salary" cell=”currency”/> 

另外,你可以声明一个定制的format并在列中通过使用列的basis来使用它,我把这想象为named属性。因此如果你的 extremecomponents.properties文件如下所示:

table.format.myCustomDate=yy-MM-dd

那么列可以如下使用定制的format:

<ec:column property="dateOfBirth" cell="date" format=”myCustomDate”>

10.4. Advanced Techniques

使用named属性是我定义其他不同属性默认值时经常使用的方法。你可能对我 使用cell="date"来指定日期cell、使用cell="currency"来指定货币cell或使用view="xls."来指定xls导出感到疑惑。 如果我给你展示extremetable.properties文件的一些片断,这些就将非常清晰了。 extremetable.properties是eXtremeTable声明默认设置的属性文件,你可以通过使用 extremecomponents.properties文件来覆盖它。

column.cell.date=org.extremecomponents.table.cell.DateCell
column.cell.currency=org.extremecomponents.table.cell.NumberCell
column.filterCell.droplist=org.extremecomponents.table.cell.FilterDroplistCell
table.view.xls=org.extremecomponents.table.view.XlsView

当你在列上定义cell="date"时,eXtremeTable寻找到column.cell. 属性并将你定义的cell属性值拼接上。 换句话说cell="date"关联到column.cell.date=org.extremecomponents.table.cell.DateCell这条属性。使用属性文件 真正强大的地方在于你能够在extremecomponents.properties文件中声明一个定制的cell,并在ColumnTag中通过 名称来使用它。

再使用一个实例来阐明这一点,是否记得ColumnTag章Cell节中如何调用一个名为MyCell的定制cell:

<ec:column property="firstName" cell="com.mycompany.cell.MyCell"/>

cell使用的更好方式是在属性文件中声明并通过名称使用它。首先,更新extremecomponents.properties文件:

table.imagePath=/extremesite/images/*.gif
table.rowsDisplayed=12
table.cellspacing=2
column.parse.date=yyyy-MM-dd
column.format.date=MM/dd/yyyy
column.format.currency=$###,###,##0.00
column.cell.myCell=com.mycompany.cell.MyCell

现在可以通过名称调用MyCell:

<ec:column property="firstName" cell="myCell"/>

正如你所见的这能帮助保持代码清洁,并且这些都在一个地方定义。如果你的定制cell声明 需要改变你只需要修改属性文件。

Chapter 11. Messages

11.1. 资源绑定

为了设置资源绑定,你应该如下例所示在/WEB-INF/web.xml文件中声明一个context-param,并 指定你的资源文件的路径:

<context-param>
  <param-name>extremecomponentsMessagesLocation</param-name>
  <param-value>org/extremesite/resource/extremecomponentsResourceBundle</param-value>
</context-param>

本示例中资源文件为extremecomponentsResourceBundle,它可以为任何名或者使用已经存在的资源文件。

如果你不指定locale,则它将根据你的servlet request来决定使用哪个资源文件。 在eXtremeTable中可以通过使用TableTag的locale属性来设置它。

<ec:table
  items="presidents"
  action="${pageContext.request.contextPath}/public/demo/locale.jsp"
  title="table.title.president"
  locale="de_DE"
  >
  ...
</ec:table>

在这里eXtremeTable将寻找德文资源文件。

11.2. 全局资源

eXtremeTable使用一些全局的keys来与用户交互,包括:状态栏的文本信息,Rows Displayed droplist和不同的tooltips。如果你足够幸运,eXtremeTable已经提供了相应的语言支持 的话,那么你什么也不用担心。否则的话,你需要申明下列keys:

statusbar.resultsFound={0} results found, displaying {1} to {2}
statusbar.noResultsFound=There were no results found.

toolbar.firstPageTooltip=First Page
toolbar.lastPageTooltip=Last Page
toolbar.prevPageTooltip=Previous Page
toolbar.nextPageTooltip=Next Page
toolbar.filterTooltip=Filter
toolbar.clearTooltip=Clear

toolbar.clearText=Clear
toolbar.firstPageText=First
toolbar.lastPageText=Last
toolbar.nextPageText=Next
toolbar.prevPageText=Prev
toolbar.filterText=Filter

column.headercell.sortTooltip=Sort By

column.calc.total=Total
column.calc.average=Average

现在仅支持英语和德语。如果你使用其他语言的话,并能提供相应的翻译的话我将不胜感激。你可以通过 extremecomponents@gmail.com发送给我。

译者注:我已经提供了中文和日文的资源文件。

11.3. TableTag

TableTag属性中能够使用locale方式指定的是:imagePath和title。

在eXtremeTable中,imagePath属性有一个特定的key:table.imagePath。你可以在你的资源文件中 设置这个key为特定语言的目录结构。例如:德文图片可能放在de文件夹下,那么你可以在相应的资源文件中 进行如下设置:

table.imagePath=/extremesite/images/table/de/*.gif

title有一点不同,如果你指定的title属性值包含dot (.)并且你定义了一个资源文件,那么 eXtremeTable将寻找匹配的key。例如,如果你像下例一样在表中指定属性title="table.title.president":

<ec:table
  items="presidents"
  action="${pageContext.request.contextPath}/public/demo/locale.jsp"
  title="table.title.president"
  >
  ...
</ec:table>

那么eXtremeTable将在属性文件中寻找匹配的key:

table.title.president=US Pr?sidenten

11.4. ColumnTag

ColumnTag属性中能够使用locale方式指定的是:format和title。

在eXtremeTable中,format属性有一个特定的key:table.fomat.type。参考属性文件的讨论 来了解更多的细节,他们具有同样的概念。日期和货币的format类型定义可能如下所示:

column.format.date=MM/dd/yyyy
column.format.currency=$###,###,##0.00

title有一点不同,如果你指定的title属性值包含dot (.)并且你定义了一个资源文件,那么 eXtremeTable将寻找匹配的key。例如,如果你像下例一样在列中指定属性title="table.column.nickName":

<ec:table
  items="presidents"
  action="${pageContext.request.contextPath}/public/demo/locale.jsp"
  title="table.title.president"
  >
  <ec:row>
    <ec:column property="nickName" title="table.column.nickName" />
  </ec:row>
</ec:table>

那么eXtremeTable将在属性文件中寻找匹配的key:

table.column.nickName=Spitzname

Chapter 12. Limit

12.1. Limit指南

默认的情况下eXtremeTable取得所有的结果集然后处理Beans集合,这样的好处是 你可以随意进行排序、过滤和分页操作。你只需要组装Beans集合并让eXtremeTable知道如何 引用它。这样的操作对于小到中等数据量的结果集非常有效,当结果集很大时这将非常糟糕。 这是一个判断,但我更喜欢描述如何做出我的技术决定。如果您认为在性能上有问题, 那么最好是使用一个profiler工具记录并查看它。有许多开源和商业的profiler工具可以帮助 你做出最好的判断。因此,假设我们发现了性能上存在问题,需要我们自己来处理分页。

手动处理分页意味着你一次只想取得一页显示需要的结果集。同时,你需要自己处理排序、过滤和分页。 下面的讨论是基于我假设你从数据库中取得集合,当然同样的原理能应用到任何地方。

这是一个重要的部分。为了得到较小的结果集,你可以创建一个普通的查询语句,但是limit你得到的结果集。 在Sybase和SQLServer中你可以使用rowcount命令,在MySql中你可以使用limit命令。 我不知道其他数据库怎么使用,但我确信每个数据库都有相似的功能。 也就是说当用户浏览第一页是得到第一页需要的 结果集,当用户浏览下一页时,再得到下一页需要的结果集。

使用Sybase的开发人员可能会说:rowcount命令总是从第一条开始,那么当我到第二页时我也必须 从第一条数据开始。 是的,你现在得到的是两页的结果集,而不需要得到所有的结果集。当你到第三页时,你只需要得到三页的结果集。。。。。。 其他数据库比如MySQL,允许你精确地得到你想要的那段数据,这样你就可以只得到当前页面显示需要的结果集。

为了知道用户想如何排序和过滤,他们想浏览哪一页,一页需要显示几条结果,eXtremeTable有一个使用LimitFactory 创建的名为Limit的简便接口:

12.2. 创建Limit

首先你需要通过LimitFactory得到一个Limit实例:

Context context = new HttpServletRequestContext(request);
LimitFactory limitFactory = new TableLimitFactory(context, tableId);
Limit limit = new TableLimit(limitFactory);

Limit对象定义了limit结果集的所有方法。

TableLimitFactory具有另外一个构造函数,如果没有指定tableId的话默认的tableId将为ec。

Context context = new HttpServletRequestContext(request);
LimitFactory limitFactory = new TableLimitFactory(context);
Limit limit = new TableLimit(limitFactory);

12.3. Filter和Sort属性

当你对Limit实例化时,实例化对象包含两个对象:FilterSet和Sort。

private FilterSet filterSet;
private Sort sort;

FilterSet包含一个过滤动作(Action)和一个过滤器对象数组。 动作为TableConstants.FILTER_ACTION或TableConstants.CLEAR_ACTION。 一个过滤器包含一个property和这个过滤器的值。

private final String action;
private final Filter[] filters;

Sort对象包含property和sortOrder。sortOrder为 TableConstants.SORT_ASC或TableConstants.SORT_DESC:

private Sort sort;

12.4. 设置页和行属性

设置行属性:

limit.setRowAttributes(totalRows, DEFAULT_ROWS_DISPLAYED);

下面是设置行属性可能用到的信息:

private int rowStart;
private int rowEnd;
private int currentRowsDisplayed;
private int page;
private int totalRows;

每个变量都有一个getter方法,我将不深入讲解属性的细节。

12.5. Setup

在你完成所有的定制工作:排序、过滤.....定制的Controller(Spring)或者Action(Struts)或者其他类似的框架后, 另外你需要创建一个callback,eXtremeTable已经提供了一个名为LimitCallback的实现。为了使用你只需要设置表 属性:retrieveRowsCallback、filterRowsCallback和sortRowsCallback:

<ec:table
  items="presidents"
  retrieveRowsCallback="limit"
  filterRowsCallback="limit"
  sortRowsCallback="limit"
  action="${pageContext.request.contextPath}/limit.run"
  title="Presidents"
  >
  <ec:row>
    <ec:column property="fullName" title="Name"/>
    <ec:column property="nickName" />
    <ec:column property="term" />
    <ec:column property="born" cell="date"/>
    <ec:column property="died" cell="date"/>
    <ec:column property="career" />
  </ec:row>
</ec:table>

使用callback需要做的唯一事情是传输集合到request,同时传输totalRows属性。 totalRows表示总行数,使用PaginationCallback.TOTAL_ROWS静态变量将易于维护。 如果JSP页面使用了两个(以上)eXtremeTable的话你可以利用tableId分别传输totalRows。 例如如果tableId名为pres,你可以如下处理:

request.setAttribute("pres", presidents);
request.setAttribute("pres_totalRows", new Integer(""+totalRows));

译者注:关于limit使用的更详细信息,请参考《Limit指南》。

Chapter 13. AutoGenerateColumns

13.1. 引言

大多数情况下你按照你需要的列来设计数据库表。但是,有时候需要运行时动态生成一些列。 为了实现这点,eXtremeTable需要使用ColumnsTag并设置autoGenerateColumns属性。

AutoGenerateColumns为singleton并且不是线程安全的,因此不要定义任何类变量。

13.2. ColumnsTag

ColumnsTag只有autoGenerateColumns这一个属性。所有你必须做的就是实现AutoGenerateColumns接口, 并设置autoGenerateColumns属性为类的全路径。

<ec:table
  items="presidents"
  action="${pageContext.request.contextPath}/autoGenerateColumns.run"
  title="Presidents"
  >
  <ec:columns autoGenerateColumns="org.extremesite.controller.AutoGenerateColumnsImpl"/>
</ec:table>

AutoGenerateColumns接口只有一个方法:

public void addColumns(TableModel model);

你需要做的就是添加列(columns)到model里。最简单的示例如下:

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);
        }
    }
}

示例中columnsToAdd()方法简单返回一个包含生成列(columns)需要的所有信息的集合。 作为参考,下面是我在eXtremeComponents网站实例中使用的columnsToAdd()方法:

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;
}

private Map columnToAdd(String property, String cell) {
  Map column = new HashMap();
  column.put(Column.PROPERTY, property);
  column.put(Column.CELL, cell);
  return column;
}

另外,我想声明的是只创建列一次。eXtremeTable为了高效,不会每行创建一列, 而是通过循环持续插入新列值到已经存在的列。记住TableModel能够访问Context,因此 你可以在Controller(Spring)或Action(Struts)中定义样式(look like)并通过request传输集合。 所以你得AutoGenerateColumns实现只需要构建列(Columns)并添加到model.columns里。

Chapter 14. Utilities

14.1. 引言

eXtremeTable包含许多Utility类。在这里我只简单地讨论一些,你可以通过javadocs 得到更多的信息。

14.2. HtmlBuilder

封装了所有html语法的类。这个简单类的使你能够写出更干净的html代码,而不用担心null或空字符串。 一个span标签的示例代码如下:

HtmlBuilder html = new HtmlBuilder();
html.span().styleClass(FORM_BUTTONS).close();
html.append(formButtons);
html.spanEnd();
return html.toString();

Chapter 15. 1.0.1-M4升级说明

15.1. 变更概述

下面的特性已经被更改:

  • HtmlView基于原来代码的实现已经deprecated

  • Cell接口更简单

  • 增加RowTag

  • AutoGenerateColumns变为singleton,更易添加列属性

  • Extended Attributes方法名变更

  • TableTag的collection属性被删除

  • BaseModel更名为TableModel

  • Properties和ResourceBundle现在为Preferences和Messages

  • pageContext被Context接口代替

  • Limit和LimitFactory的语法变更,更易于使用

  • TableTag的saveFilterSort属性被state属性代替

  • ColumnTag的showTotal属性被calc属性代替

  • search图片的名称变为filter

  • FormTag/InputTag为deprecated

  • RetrieveRowsCallbacks、FilterRowsCallback、SortRowsCallback都变为singletons

15.1.1. HtmlView

我把和旧的view相关的代码:原始的view、cell和相关代码放到deprecated文件夹。 原因是新的view代码非常成功,所以没有必要使用旧的代码。使用新代码构建定制view请参考 view包中的HtmlView或CompactView。

15.1.2. Cell

Cell接口已经改变,原因是想结束混乱以提高灵活性。以前对于如何处理区分html和export显示值 不是十分明显。现在Column值设置html,Column的propertyValue设置export。另外因为Column值和 propertyValue值被重写。现在他们在view中是不可见的。

cell现在是singleton并且不再线程安全,因此不要定义任何类变量。改变的原因是为 了Cell接口能更简单地被使用。init()和destroy()方法作为singleton更灵活但是处于一种混乱的状态。

Cell接口如下:

public interface Cell {

    /**
     * The display that will be used for the exports.
     */
    public String getExportDisplay(TableModel model, Column column);

    /**
     * The html that will be displayed in the table.
     */
    public String getHtmlDisplay(TableModel model, Column column);
}

现在得到导出和html显示存在明显的区别。更重要的,需要返回字符串。列值和属性值不再 需要设置。另一个细微的区别是:BaseModel已经被TableModel取代。这种改变是的不再需要一个 基础包(base package),这意味着不再需要BaseModel。

cell变为singleton不会导致使用复杂,如果你定义了任何类变量只需要把他们放到正确的 方法那么他们就能被任何其他方法使用。

BaseCell被删除因为不再需要添加任何值。替代的是AbstractCell,虚拟方法 getCellValue被用来返回cell的值。这种方法非常容易使用并不需要关心markup。查看 AbstractCell也是有意义的,你会发现这代码实现的多么简单。然而,很多时候需要做的仅仅是 实现Cell接口:

DisplayCell:

public class DisplayCell extends AbstractCell {
    public String getExportDisplay(TableModel model, Column column) {
        return column.getPropertyValueAsString();
    }

    protected String getCellValue(TableModel model, Column column) {
        return column.getValueAsString();
    }
}

AbstractCell:

public abstract class AbstractCell implements Cell {
    public String getExportDisplay(TableModel model, Column column) {
        return getCellValue(model, column);
    }

    public String getHtmlDisplay(TableModel model, Column column) {
        HtmlBuilder html = new HtmlBuilder();
        CellBuilder.tdStart(html, column);
        CellBuilder.tdBody(html, getCellValue(model, column));
        CellBuilder.tdEnd(html);
        return html.toString();
    }

    /**
     * A convenience method to get the display value.
     */
    protected abstract String getCellValue(TableModel model, Column column);
}

15.1.3. RowTag

RowTag<ec:row> 现在被需要,它被用来替代columns。 现在看来它一直被需要。它不知道表中到底有多少列,最近重构的时候我通过 Table -> Row -> Column使结构固定来合并得到更好的灵活性。将来我可能提供更多的 特性,因为我知道eXtremeTable有着清晰的架构。

典型的eXtremeTable如下:

<ec:table
  items="presidents"
  var="pres"
  action="${pageContext.request.contextPath}/presidents.run"
  >
  <ec:row>
    <ec:column property="name"/>
    <ec:column property="term"/>
  </ec:row>
</ec:table>

15.1.4. AutoGenerateColumns

AutoGenerateColumns得到了很大的提高,现在你只需要设置你需要的属性。 当你添加列到ColumnHandler使,defaults将别自动调用。

AutoGenerateColumns为singleton并且不是线程安全的,因此不要定义任何类变量。

现在它的实现可能如下:

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);
        }
    }
}

15.1.5. Extended Attributes

addExtendedAttributes方法重命名使得如何使用这个特性更清晰。 因此RowTag的addExtendedAttributes现在变为addRowAttributes,ColumnTag变 为addColumnAttributes,TableTag变为addTableAttributes,ExportTag变 为addExportAttributes。另外你参考正确的model bean(它的实现更清晰), 将知道如何添加属性到你的cell、view.....

使用ExportCsvTag的示例如下:

public void addExportAttributes(Export export) {
    String view = export.getView();
    if (StringUtils.isBlank(view)) {
        export.setView(TableConstants.CSV);
        export.setImageName(TableConstants.CSV);
    }
    export.addAttribute(CsvView.DELIMITER, getDelimiter());
}

为了得到delimiter属性值你只需要从Export bean中get它:

Export export = model.getExportHandler().getCurrentExport();
String delimiter = export.getAttributeAsString(DELIMITER);

现在你需要在ExportTag中覆盖它,你只需要调用setter方法。如果是新的属性,那么使用 可以和前一版一样使用addAttribute()方法。为了得到值,首先从ExportHandler得到Export, 然后调用需要的getter方法。这和使用其它tags一样。

在RowTag和ColumnTag中增加了两个新的callback方法:modifyRowAttributes和 modifyColumnAttributes,因此你可以在rows/columns被处理时改变属性值。

15.1.6. TableTag的collection属性

TableTag的collection属性被删除,现在变为三个新属性:tableId、items和var。 因为我按照标准的JSTL命名,你应该能够根据这些名称知道他们的作用。tableId属性 被用来作为表的唯一标识,items属性用来表示从各种servlet的scopes里取得的集合, var属性表示你将使用EL编写脚本的名称。

依赖你的需要来决定如何使用新的属性,tableId用来唯一标识表。如果你的页面上只使用了 一个eXtremeTable并且不使用Limit特性,那么你根本不需要定义它。默认的表示名为'ec';如果使用 Limit特性你也可以使用'ec'这个名称。然而,如果的一个JSP页面上同时使用两个eXtremeTables你就 需要使用tableId来唯一标识他们。var属性被用来你将使用EL编写脚本的名称。items属性用来表示从 各种servlet的scopes里取得的集合,而且现在非常健壮。你现在能nest集合到另外的对象,或者nest你想的 深度。

取得集合的语法如下:

<ec:table items="command.myObject.myCol" />

本示例将从命令对象(command object)取得myCol集合。

<ec:table items="myCol" />

本示例中将根据名称自动取得集合,就像以前版本的collection属性一样。

15.1.7. BaseModel

BaseModel被重命名为TableModel,这是因为已经不需要一个基础包(base package)了,这也 意味着不再需要BaseModel了。

15.1.8. Properties和ResourceBundle

web.xml文件中使用extremecomponentsPreferencesLocation属性取代extremecomponentsPropertiesLocation属性, properties现在被Preferences接口控制。在以后的版本,我将提供可选的xml文件配置。

eXtremeTable不再默认在顶层类路径(top level classpath)寻找 extremecomponents.properties文件。你应该在web.xml中使用设置context-param属性的 值为extremecomponentsPreferencesLocation,这将更为通用。

web.xml文件中使用extremecomponentsMessagesLocation属性取代extremecomponentsResourceBundleLocation属性, internationalization现在被Messages接口控制。

Properties和ResourceBundle属性根据table、row、column、export和filterare区分开。 在以前版本中每个属性都以'table'开头,现在每个属性关联到被使用的标签。另外poperty不再需要使用奇怪的下划线语法, 而是使用dot来强调。

下面为properties文件的示例:

table.imagePath=/extremesite/images/*.gif
table.rowsDisplayed=12
column.parse.date=yyyy-MM-dd
column.format.date=MM/dd/yyyy
column.format.currency=$###,###,##0.00

[英文的属性文件示例如下:]

statusbar.resultsFound={0} results found, displaying {1} to {2}
statusbar.noResultsFound=There were no results found.

toolbar.firstPageTooltip=First Page
toolbar.lastPageTooltip=Last Page
toolbar.prevPageTooltip=Previous Page
toolbar.nextPageTooltip=Next Page
toolbar.filterTooltip=Filter
toolbar.clearTooltip=Clear

toolbar.clearText=Clear
toolbar.firstPageText=First
toolbar.lastPageText=Last
toolbar.nextPageText=Next
toolbar.prevPageText=Prev
toolbar.filterText=Filter

column.headercell.sortTooltip=Sort By

column.calc.total=Total
column.calc.average=Average

15.1.9. pageContext

TableModel (以前的BaseModel)不再直接访问pageContext,取而代之的是使用Context接口, 默认的被pageContext支持。直接访问pageContext是一个不好的实现,Context提供你需要从不同servlet scopes中 取得需要属性值的所有方法。然而,如果你需要直接访问背后的对象,可以使用getContextObject()方法。

15.1.10. Limit和LimitFactory

Limit和LimitFactory现在都是接口,以前版本的实现不如我想象的简单。然而, Limit对象的方法命名和以前版本的一样,因此你以前的代码也能很好的工作。

我两个Limit实现重构为一个,但是仍有两个LimitFactory实现, 从coding的观点用户只要使用一个 实现,但是它必须兼容以前的版本。现在只有一个Limit实现我重命名为TableLimit。同时,因为Limit特性 依赖Context而不是request,我重命名工厂类(TableLimitFactory)来reflect它。

Limit在导出时正确地显示行信息,Limit具有一个isExported()方法。

使用Limit和LimitFactory的示例如下:

Context context = new HttpServletRequestContext(request);
LimitFactory limitFactory = new TableLimitFactory(context, tableId);
Limit limit = new TableLimit(limitFactory);

设置row属性,仅设置totalRows和默认的行显示:

limit.setRowAttributes(totalRows, DEFAULT_ROWS_DISPLAYED);

RequestLimitFactory具有另一个如果没有指定tableId将设置为ec的构造函数:

Context context = new HttpServletRequestContext(request);
LimitFactory limitFactory = new TableLimitFactory(context);

15.1.11. TableTag的saveFilterSort属性

saveFilterSort属性被state属性取代,state属性参照State接口并能插接不通的关于 如何保存表状态的实现。

State接口如下:

public interface State {
    public void saveParameters(TableModel model, Map parameters);
    public Map getParameters(TableModel model);
}

表新增了两个属性:state和stateAttr。state属性使用预设的四种 状态(default、notifyToDefault、persist和notifyToPersist)之一, 你也可以插接自己的实现。default状态不维持任何状态;persist状态没有任何参数传入,将一直维持表的状态; notifyToDefault状态将一直维持表的状态直到你传入参数告诉它回到default状态;notifyToPersist状态 将一直维持当前状态直到你传入参数告诉它维持persisted状态。stateAttr为指定参数提供了一条途径,你 也可以使用属性文件在全局范围内指定它。为了向后兼容,默认参数一直为useSessionFilterSort。

如果你想state按照不同方式工作你只要实现State接口,然后使用TableTag的state属性来指定实现类的 全路径。

15.1.12. ColumnTag的showTotal属性

列新增了两个属性:calc和calcTitle:

<ec:column property="data" calc="total" calcTitle="Total:" />

calc属性实现具有唯一方法的Calc接口:

public interface Calc {
    public Number getCalcResult(TableModel model, Column column);
}

它传入model和column,并返回一个Number型的值。默认的实现为总计和平均值。

为了使用定制的Calc,只需要使用ColumnTag的calc属性来指定实现Calc接口的实现类的 全路径。

Calc为singleton并且不是线程安全的,因此不要定义任何类变量。

showTotal因为不再适用在新版中被删除,我也删除了表中的totalTitle。

15.1.13. Image名

search图片名从search变为filter。

15.1.14. FormTag / InputTag Deprecated

FormTag和InputTag现在为deprecated。他们在新的html视图(view)中不再被使用。

15.1.15. RetrieveRowsCallbacks、FilterRowsCallback、SortRowsCallback

Callbacks为singleton并且不是线程安全的,因此不要定义任何类变量。

Chapter 16. Tag Attributes

16.1. TableTag

Table 16.1. 

NameDescription
actionThe URI that will be called when the filter, sort and pagination is used.
autoIncludeParametersSpecify whether or not to automatically include the parameters, as hidden inputs, passed into the JSP.
borderThe table border attribute. The default is 0.
cellpaddingThe table cellpadding attribute. The default is 0.
cellspacingThe table cellspacing attribute. The default is 0.
filterableSpecify whether or not the table is filterable. Boolean value with the default being true.
filterRowsCallbackA fully qualified class name to a custom FilterRowsCallback implementation. Could also be a named type in the preferences. Used to filter the Collection of Beans or Collection of Maps.
formThe reference to a surrounding form element.
imagePathThe path to find the images. For example imagePath=/extremesite/images/*.png is saying look in the image directory for the .png images.
interceptA fully qualified class name to a custom InterceptTable implementation. Could also be a named type in the preferences. Used to add table attributes.
itemsReference the collection that will be retrieved.
localeThe locale for this table. For example fr_FR is used for the French translation.
methodUsed to invoke the table action using a POST or GET.
onsubmitThe javascript onsubmit action for the table.
retrieveRowsCallbackA fully qualified class name to a custom RetrieveRowsCallback implementation. Could also be a named type in the preferences. Used to retrieve the Collection of Beans or Collection of Maps.
rowsDisplayedThe number of rows to display in the table.
scopeThe scope (page, request, session, or application) to find the Collection of beans or Collection of Maps defined by the collection attribute.
showPaginationSpecify whether or not the table should use pagination. Boolean value with the default being true.
showExportsSpecify whether or not the table should use the exports. Boolean value with the default being true.
showStatusBarSpecify whether or not the table should use the status bar. Boolean value with the default being true.
showTooltipsSpecify whether or not to show the tooltips. Boolean value with the default being true.
sortRowsCallbackA fully qualified class name to a custom SortRowsCallback implementation. Could also be a named type in the preferences. Used to sort the Collection of Beans or Collection of Maps.
sortableSpecify whether or not the table is sortable. Boolean value with the default being true.
stateThe table state to use when returning to a table. Acceptable values are default, notifyToDefault, persist, notifyToPersist.
stateAttrThe table attribute used to invoke the state change of the table.
styleThe css inline style sheet.
styleClassThe css class style sheet.
tableIdThe unique identifier for the table.
themeThe theme to style the table. The default is eXtremeTable.
titleThe title of the table. The title will display above the table.
varThe name of the variable to hold the current row bean.
viewGenerates the output. The default is the HtmlView to generate the HTML. Also used by the exports to generate XLS-FO, POI, and CSV.
widthWidth of the table.

16.2. RowTag

Table 16.2. 

NameDescription
highlightClassThe css class style sheet when highlighting rows.
highlightRowUsed to turn the highlight feature on and off. Acceptable values are true or false. The default is false.
interceptA fully qualified class name to a custom InterceptRow implementation. Could also be a named type in the preferences. Used to add or modify row attributes.
onclickThe javascript onclick action
onmouseoutThe javascript onmouseout action
onmouseoverThe javascript onmouseover action
styleThe css inline style sheet.
styleClassThe css class style sheet.

16.3. ColumnTag

Table 16.3. 

NameDescription
aliasUsed to uniquely identify the column when the same property is used for more than one column.
calcA fully qualified class name to a custom Calc implementation. Could also be a named type in the preferences. Used to do math on a column.
calcTitleThe title of the calc.
cellDisplay for the column. The valid values are display, currency, rowCount, and date. The default value is display. The cell can also be a fully qualified class name to a custom Cell. Be sure to implement the Cell interface or extend AbstractCell if making a custom cell.
escapeAutoFormatSpecify whether auto format of value will be skipped. False by default, and is only effective if autoformatting is implement in the view.
filterableSpecify whether or not the column should be filterable. Acceptable values are true or false. The default is to use the value for the table filterable attribute.
filterCellDisplays the filter column. The valid values are filter and droplist. The default is filter. The cell can also be a fully qualified class name to a custom cell.
filterClassThe css class style sheet used to define what the table filter column looks like.
filterStyleThe css class style sheet to use for the filter column.
formatThe format to use for the cell. For instance if used with a date cell then the format can be MM/dd/yyyy.
headerCellDisplay for the header column. The default is header. The cell can also be a fully qualified class name to a custom cell.
headerClassThe css class style sheet used to define what the table header column looks like.
headerStyleThe css class style sheet to use for the header column.
interceptA fully qualified class name to a custom InterceptColumn implementation. Could also be a named type in the preferences. Used to add or modify column attributes.
parseUsed if the format needs to be interpreted. For instance, a date needs to be parsed in the specific format, such as MM-dd-yyyy.
propertyThe bean attribute to use for the column.
sortableSpecify whether or not the column should be sortable. The acceptable values are true or false. The default is to use the value for the table sortable attribute.
styleThe css inline style sheet.
styleClassThe css class style sheet.
titleThe display for the table column header. If the title is not specified then it will default to the name of the property, changing the camelcase syntax to separate words.
valueThe value for the column. If the value attribute is not specifed then it will be retrieved automatically using the property attribute. The value can also be defined within the column body.
viewsAllowedThe comma separated list of views that this column will be used in.
viewsDeniedThe comma separated list of views that this column will not be used in.
widthSpecify the column width.

16.4. ExportTag

Table 16.4. 

NameDescription
fileNameThe name of the export file.
imageNameThe image name.
interceptA fully qualified class name to a custom InterceptExport implementation. Could also be a named type in the preferences. Used to add or modify export attributes.
viewA fully qualified class name to a custom View implementation. Could also be a named type in the preferences. Default types are pdf, xls, or csv.
viewResolverA fully qualified class name to a custom ViewResolver implementation. Could also be a named type in the preferences. Default types are pdf, xls, or csv.
textThe text for the export view.
tooltipThe tooltip that shows up when you mouseover the export image.

16.5. ExportXlsTag

Table 16.5. 

NameDescription
fileNameThe name of the export file.
imageNameThe image name.
interceptA fully qualified class name to a custom InterceptExport implementation. Could also be a named type in the preferences. Used to add or modify export attributes.
viewA fully qualified class name to a custom View implementation. Could also be a named type in the preferences. Default types are pdf, xls, or csv.
viewResolverA fully qualified class name to a custom ViewResolver implementation. Could also be a named type in the preferences. Default types are pdf, xls, or csv.
textThe text for the export view.
tooltipThe tooltip that shows up when you mouseover the export image.

16.6. ExportCsvTag

Table 16.6. 

NameDescription
delimiterWhat to use as the file delimiter. The default is a comma.
fileNameThe name of the export file.
imageNameThe image name.
interceptA fully qualified class name to a custom InterceptExport implementation. Could also be a named type in the preferences. Used to add or modify export attributes.
viewA fully qualified class name to a custom View implementation. Could also be a named type in the preferences. Default types are pdf, xls, or csv.
viewResolverA fully qualified class name to a custom ViewResolver implementation. Could also be a named type in the preferences. Default types are pdf, xls, or csv.
textThe text for the export view.
tooltipThe tooltip that shows up when you mouseover the export image.

16.7. ExportPdfTag

Table 16.7. 

NameDescription
headerBackgroundColorThe background color on the header column.
headerColorThe font color for the header column.
headerTitleThe title displayed at the top of the page.
fileNameThe name of the export file.
imageNameThe image name.
interceptA fully qualified class name to a custom InterceptExport implementation. Could also be a named type in the preferences. Used to add or modify export attributes.
viewA fully qualified class name to a custom View implementation. Could also be a named type in the preferences. Default types are pdf, xls, or csv.
viewResolverA fully qualified class name to a custom ViewResolver implementation. Could also be a named type in the preferences. Default types are pdf, xls, or csv.
textThe text for the export view.
tooltipThe tooltip that shows up when you mouseover the export image.

16.8. ColumnsTag

Table 16.8. 

NameDescription
autoGenerateColumnsA fully qualified class name to a custom AutoGenerateColumns implementation. Could also be a named type in the preferences. Used to generate columns on the fly.

16.9. ParameterTag

Table 16.9. 

NameDescription
nameThe name of the parameter.
valueThe value of the parameter.

 原文地址 http://www.blogjava.net/lucky/articles/33380.html
发表于: 2007-11-20,修改于: 2007-11-20 14:06,已浏览955次,有评论0条 推荐 投诉


网友评论
 发表评论