---
title: "eXtremeComponents"
author: "mhbjava"
date: "2006-09-08T15:25:00Z"
tags: []
slug: "extremecomponents"
draft: false
lastmod: "2006-09-08T15:25:00Z"
id: 26591
url: "https://mhbjava.iteye.com/blog/26591"
---

1\.  
&lt;ec:table  
items="presidents"  
var="pres"  
imagePath="${pageContext.request.contextPath}/images/\*.gif"  
action="${pageContext.request.contextPath}/presidents.run"  
filterable="false"   
sortable="false"  &gt;   
...  
&lt;/ec:table&gt;

&lt;ec:table&gt;里的属性还有:  
a.   rowsDisplayed,rowsDisplayed也可以在extremecomponents.properties文件中设定  
b.   showPagination ,如果你想在一页中显示所有行，只需要设置showPagination为false。  
c.   TableTag关联了很多样式属性：

 &lt;ec:table  cellspacing="0"  cellpadding="0"  border="0"  width="80%"  style=""  styleClass=""  /&gt;  
 所有这些都是可选的。

2\.  
使用highlightRow属性可以设置行的高亮显示，它的值为true或false，默认值为false。

&lt;ec:table  items="presidents"  var="pres"  action="${pageContext.request.contextPath}/presidents.run"  &gt;   
 &lt;ec:row highlightRow="true"&gt;     
  &lt;ec:column property="name"/&gt;    
  &lt;ec:column property="term"/&gt;  
 &lt;/ec:row&gt;  
&lt;/ec:table&gt;  
设置highlightRow属性后，它将插入设置行css类的javascript脚本，默认的css 类为highlight。你可以使用highlightClass来使用定制的css类。

3\.  
为了便于你对于行数据进行动态交互处理，提供了onclick、onmouseover和 onmouseout属性。

&lt;ec:row  onclick=""  onmouseover=""  onmouseout=""  /&gt;

4\.  
RowTag关联了很多样式属性：

&lt;ec:row  style=""  styleClass=""  highlightClass=""  /&gt;

5\.

提供可选取值方法的主要原因是使你能够对其他类型的html标签提供动作支持，例如显示 一幅图片或者通过定义href使该列成为到其它页的一个链接。

&lt;ec:table  items="presidents"  var="pres"  action="${pageContext.request.contextPath}/presidents.run"  &gt;  
 &lt;ec:row&gt;     
  &lt;ec:column property="lastName"&gt;       
  &lt;a href="[http://goto.president.detail"&gt;${pageScope.pres.lastName}&lt;/a](http://goto.president.detail"%3E${pageScope.pres.lastName}%3C/a)&gt;    
  &lt;/ec:column&gt;  
 &lt;/ec:row&gt;  
&lt;/ec:table&gt;

6。  
&lt;ec:column property="time" title="时间" parse="yyyy-MM-dd" format="yyyy年MM月dd日" cell="date"/&gt;

7。  
TableTag中有filterable和sortable属性，ColumnTag中也有相同的属性。 列的filterable和sortable属性将覆盖表的filterable和sortable属性设置。当你需要除了对表中的一、两列之外的 所有列进行过滤和排序时，十分便利。

&lt;ec:table  items="presidents"  action="${pageContext.request.contextPath}/presidents.run"  &gt;  
 &lt;ec:row&gt;     
  &lt;ec:column property="firstName" filterable="false"/&gt;   
  &lt;ec:column property="lastName" sortable="false"/&gt;  
 &lt;/ec:row&gt;  
&lt;/ec:table&gt;

8。视图问题：

viewsAllowed属性制定类允许使用的视图。视图包括：html、pdf、xls、csv，以及任何定制的视图。 如果你指定一个或几个视图，那么列仅能使用这些指定的视图。例如：你指定viewsAllowed="pdf"，这意味着 这列只允许PDF导出，而不能进行其他格式的导出或html视图。

&lt;ec:table  items="presidents"  action="${pageContext.request.contextPath}/presidents.run"  &gt;  
 &lt;ec:row&gt;    
  &lt;ec:column property="firstName"/&gt;   
  &lt;ec:column property="lastName" viewsAllowed="pdf"/&gt;  
 &lt;/ec:row  
&lt;/ec:table&gt;  
viewsDenied属性制定类不允许使用的视图。视图包括：html、pdf、xls、csv，以及任何定制的视图。 如果你指定一个或几个视图，那么列仅这些指定的视图不能被使用。例如：你指定viewsDenied="html"，这意味着 这列不允许使用html试图，但能进行任何形式的导出。

&lt;ec:table  items="presidents"  action="${pageContext.request.contextPath}/presidents.run"  &gt;  
 &lt;ec:row&gt;   
  &lt;ec:column property="firstName"/&gt;   
  &lt;ec:column property="lastName" viewsDenied="html"/&gt;  
 &lt;/ec:row&gt;  
&lt;/ec:table&gt;

9。ParameterTag

eXtremeTable能够指定是否处理所有的参数。默认为处理所有的参数，这意味着当你进行 过滤、排序、分页时，所有的参数都被eXtremeTable保存并传到JSP中。通常这是你需要的功能， 然而，有时候你需要只允许一些特定的参数保存到eXtremeTable中。我喜欢把它看作锁定extremeTable， 可以通过设置表的autoIncludeParameters属性值为false来到达目的：

&lt;ec:table  items="presidents"  action="${pageContext.request.contextPath}/presidents.run"  autoIncludeParameters=”false”  &gt;   
...  
&lt;/ec:table&gt;  
甚至当表被锁定时，你仍然可以通过简单地使用parameter标签来包含一些你想使用的参数。下例 包含了foo参数：

&lt;ec:table  items="presidents"  action="${pageContext.request.contextPath}/presidents.run"  autoIncludeParameters=”false”  &gt;  
 &lt;ec:parameter name=”foo” value=”${param.foo}”/&gt;  
 ...  
&lt;/ec:table&gt;  
现在所有的eXtremeTable参数都被锁定。但过滤、排序和翻页时，foo参数仍将被传递。

10\. .propeties取代

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

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

&lt;context-param&gt;  &lt;param-name&gt;extremecomponentsPreferencesLocation&lt;/param-name&gt;  &lt;param-value&gt;/org/extremesite/resource/extremecomponents.properties&lt;/param-value&gt;&lt;/context-param&gt;  
你可以认为属性文件为你提供了一个对所有的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中添加他们。典型的表如下所示：

&lt;ec:table  items="presidents"  action="${pageContext.request.contextPath}/presidents.run"  imagePath="${pageContext.request.contextPath}/images/\*.gif"  rowsDisplayed="12"  title="Presidents"  &gt;  ...&lt;/ec:table&gt;  
如果在属性文件声明imagePath和rowsDisplayed，则表如下所示：

&lt;ec:table  items="presidents"  action="${pageContext.request.contextPath}/presidents.run"  title="Presidents"  &gt;  ...&lt;/ec:table&gt;  
正如你所见，属性文件避免了重复编码。

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

&lt;ec:column property="dateOfBirth" cell=”date” parse=”yyyy-MM-dd” format=”MM/dd/yyyy”/&gt;  
如果在属性文件声明parse和format，则列如下所示：

&lt;ec:column property="dateOfBirth" cell=”date”/&gt;  
当然你仍然可以定义parse和format属性来覆盖全局设置，但是大多数工程对于日期使用一致的parse 和format。需要注意属性文件中parse.date和format.date的声明语法。

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

&lt;ec:column property="salary" cell=”currency” format=”$###,###,##0.00”/&gt;  
如果在属性文件声明format，则列如下所示：

&lt;ec:column property="salary" cell=”currency”/&gt;  
另外，你可以声明一个定制的format并在列中通过使用列的basis来使用它，我把这想象为named属性。因此如果你的 extremecomponents.properties文件如下所示：

table.format.myCustomDate=yy-MM-dd  
那么列可以如下使用定制的format：

&lt;ec:column property="dateOfBirth" cell="date" format=”myCustomDate”&gt;

 

11。ExportTag

eXtremeTable具有导出不同格式文件的功能，导出的数据为过滤和排序后的所有结果集， 分页不会影响返回的结果集。换句话说，如果表数据分多页显示，那么所有页的数据都将被导出。 导出的格式为Microsoft Excel (OpenOffice Calc)、PDF和CSV。

使用ExportXlsTag导出Microsoft Excel (OpenOffice Calc)：

&lt;ec:table  items="presidents"  action="${pageContext.request.contextPath}/presidents.run"  /&gt;  
 &lt;ec:exportXls    fileName="presidents.xls"    tooltip="Export Excel"/&gt;  
 ...  
&lt;/ec:table&gt;  
使用ExportPdfTag导出PDF。所有要做的就是指定fileName属性和一些样式属性：

&lt;ec:table  items="presidents"  action="${pageContext.request.contextPath}/presidents.run"  /&gt;  
 &lt;ec:exportPdf    fileName="presidents.pdf"    tooltip="Export PDF"    headerColor="blue"    headerBackgroundColor="red"    headerTitle="Presidents"/&gt;  ...  
&lt;/ec:table&gt;  
使用ExportCsvTag导出CSV。当使用CSV导出是默认的分隔符为‘,’(comma)。你可以使用 delimiter属性来指定为其他的符号。下面为指定‘|’（pipe）为CSV分隔符的示例：

&lt;ec:table  items="presidents"  action="${pageContext.request.contextPath}/presidents.run"  /&gt;   
 &lt;ec:exportCsv    fileName="presidents.txt"    tooltip="Export CSV"    delimiter="|"/&gt;  
 ...  
&lt;/ec:table&gt;