---
title: "eXtremeComponents 表配置"
author: "rickycm"
date: "2010-02-24T01:33:49Z"
tags: []
categories: ["Web前端"]
slug: "extremecomponents"
draft: false
lastmod: "2010-02-24T01:33:49Z"
id: 601112
url: "https://rickycm.iteye.com/blog/601112"
---

转自：http://mhbjava.iteye.com/blog/26591

1.
<ec:table 
items="presidents" 
var="pres" 
imagePath="${pageContext.request.contextPath}/images/*.gif" 
action="${pageContext.request.contextPath}/presidents.run" 
filterable="false" 
sortable="false" > 
...
</ec:table>

<ec:table>里的属性还有:
a.   rowsDisplayed,rowsDisplayed也可以在extremecomponents.properties文件中设定
b.   showPagination ,如果你想在一页中显示所有行，只需要设置showPagination为false。
c.   TableTag关联了很多样式属性：

<ec:table cellspacing="0" cellpadding="0" border="0" width="80%"   styleClass="" />
所有这些都是可选的。


2.
使用highlightRow属性可以设置行的高亮显示，它的值为true或false，默认值为false。

<ec:table items="presidents" var="pres" action="${pageContext.request.contextPath}/presidents.run" > 
<ec:row highlightRow="true">    
   <ec:column property="name"/>   
   <ec:column property="term"/> 
</ec:row>
</ec:table>
设置highlightRow属性后，它将插入设置行css类的javascript脚本，默认的css 类为highlight。你可以使用highlightClass来使用定制的css类。

3.
为了便于你对于行数据进行动态交互处理，提供了onclick、onmouseover和 onmouseout属性。

<ec:row onclick="" onmouseover="" onmouseout="" />


4.
RowTag关联了很多样式属性：

<ec:row   styleClass="" highlightClass="" />


5.

提供可选取值方法的主要原因是使你能够对其他类型的html标签提供动作支持，例如显示 一幅图片或者通过定义href使该列成为到其它页的一个链接。

<ec:table items="presidents" var="pres" action="${pageContext.request.contextPath}/presidents.run" > 
<ec:row>    
   <ec:column property="lastName">      
   <a href="http://goto.president.detail">${pageScope.pres.lastName}</a>   
   </ec:column> 
</ec:row>
</ec:table>


6。
<ec:column property="time" title="时间" parse="yyyy-MM-dd" format="yyyy年MM月dd日" cell="date"/>


7。
TableTag 中有filterable和sortable属性，ColumnTag中也有相同的属性。列的filterable和sortable属性将覆盖表的filterable和sortable属性设置。当你需要除了对表中的一、两列之外的所有列进行过滤和排序时，十分便利。

<ec:table items="presidents" action="${pageContext.request.contextPath}/presidents.run" >
<ec:row>    
   <ec:column property="firstName" filterable="false"/> 
   <ec:column property="lastName" sortable="false"/> 
</ec:row>
</ec:table>


8。视图问题：

viewsAllowed 属性制定类允许使用的视图。视图包括：html、pdf、xls、csv，以及任何定制的视图。如果你指定一个或几个视图，那么列仅能使用这些指定的视图。例如：你指定viewsAllowed="pdf"，这意味着这列只允许PDF导出，而不能进行其他格式的导出或html视图。

<ec:table items="presidents" action="${pageContext.request.contextPath}/presidents.run" > 
<ec:row>   
   <ec:column property="firstName"/> 
   <ec:column property="lastName" viewsAllowed="pdf"/> 
</ec:row
</ec:table>
viewsDenied 属性制定类不允许使用的视图。视图包括：html、pdf、xls、csv，以及任何定制的视图。如果你指定一个或几个视图，那么列仅这些指定的视图不能被使用。例如：你指定viewsDenied="html"，这意味着这列不允许使用html试图，但能进行任何形式的导出。

<ec:table items="presidents" action="${pageContext.request.contextPath}/presidents.run" >
<ec:row> 
   <ec:column property="firstName"/> 
   <ec:column property="lastName" viewsDenied="html"/> 
</ec:row>
</ec:table>


9。ParameterTag

eXtremeTable 能够指定是否处理所有的参数。默认为处理所有的参数，这意味着当你进行过滤、排序、分页时，所有的参数都被eXtremeTable保存并传到JSP中。通常这是你需要的功能，然而，有时候你需要只允许一些特定的参数保存到eXtremeTable中。我喜欢把它看作锁定extremeTable，可以通过设置表的autoIncludeParameters属性值为false来到达目的：

<ec:table items="presidents" action="${pageContext.request.contextPath}/presidents.run" autoIncludeParameters=”false” > 
...
</ec:table>
甚至当表被锁定时，你仍然可以通过简单地使用parameter标签来包含一些你想使用的参数。下例 包含了foo参数：

<ec:table items="presidents" action="${pageContext.request.contextPath}/presidents.run" autoIncludeParameters=”false” > 
<ec:parameter name=”foo” value=”${param.foo}”/> 
...
</ec:table>
现在所有的eXtremeTable参数都被锁定。但过滤、排序和翻页时，foo参数仍将被传递。


10. .propeties取代

为了替代硬编码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

在属性文件定义的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>
正如你所见，属性文件避免了重复编码。


在属性文件定义的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”>

11。ExportTag

eXtremeTable 具有导出不同格式文件的功能，导出的数据为过滤和排序后的所有结果集，分页不会影响返回的结果集。换句话说，如果表数据分多页显示，那么所有页的数据都将被导出。 导出的格式为Microsoft Excel (OpenOffice Calc)、PDF和CSV。

使用ExportXlsTag导出Microsoft Excel (OpenOffice Calc)：

<ec:table items="presidents" action="${pageContext.request.contextPath}/presidents.run" /> 
<ec:exportXls    fileName="presidents.xls"    tooltip="Export Excel"/> 
...
</ec:table>
使用ExportPdfTag导出PDF。所有要做的就是指定fileName属性和一些样式属性：

<ec:table items="presidents" action="${pageContext.request.contextPath}/presidents.run" />
<ec:exportPdf    fileName="presidents.pdf"    tooltip="Export PDF"    headerColor="blue"    headerBackgroundColor="red"    headerTitle="Presidents"/> ...
</ec:table>
使用ExportCsvTag导出CSV。当使用CSV导出是默认的分隔符为‘,’(comma)。你可以使用 delimiter属性来指定为其他的符号。下面为指定‘|’（pipe）为CSV分隔符的示例：

<ec:table items="presidents" action="${pageContext.request.contextPath}/presidents.run" /> 
<ec:exportCsv    fileName="presidents.txt"    tooltip="Export CSV"    delimiter="|"/> 
...
</ec:table>