eXtremeComponents 使用總結

前言

eXtremeComponents是一系列提供高級顯示的開源JSP定製標籤。當前的包含 的組件爲eXtremeTable,用於以表的形式顯示數據。

本文檔處於更新中。大部分章節我將僅僅描述如何使用eXtremeTable。當然, 爲了使程序高效並具有更高的靈活性,源代碼被再三重構。隨後, 我認爲闡述一下如 何做設計決定是值得的。我希望大家能知道使用extremeTable是多麼容易,並且所 有的東西都是可配置。如果你有任何的要求和建議, 請及時通過論壇或者 [email protected]和我聯繫。

我想感謝Chris Bauer(Hibernate開發小組)和Rod Johnson(Spring開發小組)。 Chris提供並修改了DocBook-XSL使它能生成Hibernate參考指南。Rod對於使用從Hibernate 得到的這個軟件來生成Spring文檔提供了支持。我現在用它來生成eXtremeComponents的文檔。

譯者注:如果大家有什麼疑問和建議,可以通過[email protected]和我聯繫。
Chapter 1. 配置
1.1. 先決條件

    Servlet 2.3或更高版本

    JDK 1.3.1或更高版本

最小的Jars要求:

    commons-beanutils 1.6

    commons-collections 3.0

    commons-lang 2.0

    commons-logging 1.0.4

    standard 1.0.2

PDF導出需要的Jars:

    minimum jars (above)

    avalon-framework 4.0

    batik 1.5-fop-0.20-5

    fop 0.20.5

    xalan 2.5.1

    xercesImpl 2.6.1

    xml-apis 2.0.2

XLS導出需要的Jars:

    minimum jars (above)

    poi-2.5.1.jar

1.2. 安裝

從sourceforge 下載發行包。(http://sourceforge.net/projects/extremecomp/)

在壓縮文件裏你能找到開始使用需要的所有東西:

    extremecomponents.jar

    extremecomponents.tld

    extremecomponents.css

    默認的一組圖片

    源代碼

    test.jsp (用於確認安裝是否正確)

將extremecomponents.jar文件拷貝到你的工程的/WEB-INF/lib目錄下。

處理TLD文件有兩種方式。 你可以把extremecomponents.tld文件放到WEB-INF目錄下的任何地方。 不過,爲了便於管理,我喜歡把我的TLD文件都放到/WEB-INF/tld目錄下。你需要根據你的extremecomponents.tld 文件的位置來修改/WEB-INF/web.xml文件的標籤映射。

<taglib>
    <taglib-uri>/tld/extremecomponents</taglib-uri>
    <taglib-location>/WEB-INF/tld/extremecomponents.tld</taglib-location>
</taglib>

隨後,你需要向下面一樣在你的JSP裏把eXtremeTable包含進來:

<%@ taglib uri="/tld/extremecomponents" prefix="ec" %>

如果你的servlet容器支持JSP 1.2 (或更高版本),它將能夠自動發現TLD文件,那麼你什麼也不需要做。 當extremecomponents.jar被容器加載的時候,在它的META-INF目錄下的extremecomponents.tld文件將被找到。 這時,你需要向下面一樣在你的JSP裏把eXtremeTable包含進來:

<%@ taglib uri="http://www.extremecomponents.org" prefix="ec" %>

爲了使用eXtremeTable樣式,從styles目錄拷貝extremecomponents.css到你存放.css腳本的地方。 當然在JSP頁面裏,你需要提供一個到CSS的鏈接。就像我將我的樣式表放在/styles目錄下。

<%@ taglib uri="/tld/c" prefix="c" %>
<link rel="stylesheet" type="text/css" href="<c:url value="/styles/extremecomponents.css"/>">

1.3. 導出過濾器(可選)

爲了使導出功能有效,你需要設置導出過濾器。這是一個僅用於導出功能的可選配置。

如下所示在/WEB-INF/web.xml裏配置過濾器:

<filter>
  <filter-name>eXtremeExport</filter-name>
  <filter-class>org.extremecomponents.table.filter.ExportFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>eXtremeExport</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

過濾器還有一個可選的初始化參數,用於決定什麼時候生成報頭(headers)。我發現大多數的servlet容器 傾向於在調用過濾器的doFilter()方法後才設置響應報頭(response headers)。然而,一些servlet容器只有在 調用過濾器的doFilter()方法前設置響應報頭,過濾器才能正常工作。默認的方法是調用過濾器的doFilter()方法後 設置響應報頭,你可以通過使用responseHeadersSetBeforeDoFilter這個初始化參數調整它。

<filter>
  <filter-name>eXtremeExport</filter-name>
  <filter-class>org.extremecomponents.table.filter.ExportFilter</filter-class>
    <init-param>
      <param-name>responseHeadersSetBeforeDoFilter</param-name>
      <param-value>true</param-value>
    </init-param>
</filter>

如果你使用了Sitemesh,你將需要包含SitemeshPageFilter。SitemeshPageFilter擴展了正常的 sitemesh的PageFilter,它使得正在進行導出的JSP頁面不被修飾。

如下所示在/WEB-INF/web.xml裏配置過濾器:

<filter>
  <filter-name>Sitemesh</filter-name>
  <filter-class>org.extremecomponents.table.filter.SitemeshPageFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>Sitemesh</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

1.4. 安裝測試

使用發行包的test.jsp來測試安裝。將test.jsp拷貝到web應用的最頂層, 默認的圖片文件在 /images/table/子目錄下。爲了測試,創建相應的目錄並將拷貝所有需要的圖片。所有工作都完成後,你可以在瀏覽 器裏運行test.jsp了。

提示: 我不提倡在JSP裏使用腳本(scriplets),但爲了不用使用框架而能進行快速測試,在test.jsp 使用腳本是唯一的辦法。
Chapter 2. 概述
2.1. 引言

eXtremeTable在給定的servlet範圍(scope)外取得Beans或Maps的集合用於JSP頁面顯示。 servelet範圍的搜索順序是:page, request, session和application。通過設定TableTage的items 屬性,eXtremeTable知道哪些需要在servlet範圍外被保持。

集合裏的Beans是pojo,如果使用maps那麼它就是鍵值對。你可以認爲每一個bean就是表中的一行數據。 在接下來的文檔中,我將使用Beans集合來代替這兩種集合。

實際表使用的最小語法如下所示:

<ec:table
   items="presidents"
   action="${pageContext.request.contextPath}/presidents.run"
   imagePath="${pageContext.request.contextPath}/images/*.gif">
  <ec:row>
    <ec:column property="firstName"/>
    <ec:column property="lastName"/>
    <ec:column property="termDate"/>
  </ec:row>
</ec:table>

這就是eXtremeTable的一個典型定義。通過這些定義,你將得到格式化的列和頁頭,工具欄的所有 特性也能很好工作。
Chapter 3. TableTag
3.1. 引言

TableTag用來設定什麼被顯示並且如何進行顯示。默認的eXtremeTable在servlet範圍(按照page,request, session,applicaton的順序)尋找具有名稱和items屬性設置相同的Beans集合(如前章所述它指Beans和Maps兩種集合)。 表將遍歷所有列,它使用var屬性將當前行對應的bean從集合傳到page範圍,因此你可以從page範圍中重新得到這些數據 進行操作。tableId用來唯一標識表,如果在JSP頁面裏包含兩個或兩個以上的表時需要設置它。

President bean定義如下:

public class President implements Serializable {
  private String firstName;
  private String lastName;

  public String getFirstName() {
    return firstName;
  }

  public void setFirstName(String firstName) {
    this.firstName = firstName;
  }

  public String getLastName() {
    return lastName;
  }

  public void setLastName(String lastName) {
    this.lastName = lastName;
  }
}

Beans集合需要被組裝並傳到servlet範圍中。我喜歡使用Spring框架,因此示例將使用Spring框架的 控制器(Controller)。如果你正在使用Struts,它和Action的功能類似。如果你使用別的東西,比如直接使用 servlets,你只需要明白我所做的只是組裝Beans集合並傳到request範圍中。

public class Presidents extends AbstractController {
  protected ModelAndView handleRequestInternal(HttpServletRequest request,
                                                 HttpServletResponse response)
    throws Exception {
    List presidents = new ArrayList();

    President president = new President();

    president.setFirstName("George");
    president.setLastName("Washington");
    presidents.add(president);

    president = new President();
    president.setFirstName("John");
    president.setLastName("Adams");
    presidents.add(president);

    request.setAttribute("presidents", presidents);

    return new ModelAndView("/demo/presidents.jsp");
}

現在你可以構造表了:

<%@ taglib uri="/tld/extremecomponents" prefix="ec" %>

<ec:table
  items="presidents"
  var="pres"
  imagePath="${pageContext.request.contextPath}/images/*.gif"
  action="${pageContext.request.contextPath}/presidents.run"
  >
  <ec:column property="firstName"/>
  <ec:column property="lastName"/>
    ${pres.lastName}
  </ec:column>
</ec:table>

從本示例中你應該知道我們將名爲presidents的Beans集合以presidents爲名稱放到request中。 爲了使表知道如何找到這個Beans集合,我們設置TableTag的items屬性爲presidents。同時我們定義 了兩列:firstName和lastName。firstName列是最普通的用法:我們僅僅想讓這列從當前bean中得到相應 firstName的值;lastName列示另外一種用法:明確取得值。

從一列中明確取得值非常有用,但是你需要理解表是如何構造行的。爲了構造行,表需要對所有行進行 rowsDisplayed屬性設定次數的迭代。每次迭代都從Beans裏取得下一個bean並使用var屬性設定的名稱傳入page 範圍。也可以說每次迭代你都訪問的是集合中當前行對應的bean。
3.2. 顯示圖片

爲了顯示圖片需要設置imagePath屬性:

<ec:table
  items="presidents"
  var="pres"
  imagePath="${pageContext.request.contextPath}/images/*.gif"
  >
  ...
</ec:table>

eXtremeTable將找到一個目錄下的所有圖片並使用特殊的語法來定義他們是那類圖片。 本示例中所有的圖片都直接保存在web上下文的images目錄下。*.gif使eXtremeTable知道所 有的圖片都是GIF格式的。在我們討論preferences後,你將發現你可以你可以通過在 extremecomponents.properties文件中設定這個屬性,而不用再整個應用的每個eXtremeTable 中包含它。
3.3. 過濾、排序和動作(Action)

eXtremeTable內嵌了過濾和排序功能,你只需要決定是否需要使用他們。你要使用的屬性是 filterable和sortable,他們都是布爾值並且默認值是true。默認的所有特性都有效,你可以按照 需要來關掉一些特性。比如,如果你不想使用排序或過濾你可以把他們的屬性設爲false。

<ec:table
  items="presidents"
  var="pres"
  imagePath="${pageContext.request.contextPath}/images/*.gif"
  action="${pageContext.request.contextPath}/presidents.run"
  filterable="false"
  sortable="false"
  >
  ...
</ec:table>

如果你仍不確信,你可以來驗證他們。首先,設置filterable和sortable爲true,你將看到 eXtremeTable允許你輸入關鍵詞來過濾結果集,它也允許你通過在頁頭(header)上滾動鼠標來排序。 然後,設置filterable和sortable爲fale,你將發現所有這些特性都不允許使用。

本示例需要指出的是使用action屬性,action被用來告訴eXtremeTable當過濾或排序時如何回 到當前的頁面。本例中我通過Spring框架的controller(在這裏是presidents.run)來得到Beans集合。 你不需要擔心傳參問題,eXtremeTable將保存所有的參數並將它們和過濾器、排序、分頁一起傳遞給 Beans集合。更詳細的信息請參考ParameterTag。
3.4. 設定每頁顯示行數

默認地eXtremeTable一頁將顯示15行。你可以通過設定rowsDisplayed屬性爲你想顯示行數的數 值來改變它。rowsDisplayed也可以在extremecomponents.properties文件中設定。(參考Preferences)。

提示:如果你想在一頁中顯示所有行,只需要設置showPagination爲false。
3.5. 樣式

TableTag關聯了很多樣式屬性:

<ec:table
  cellspacing="0"
  cellpadding="0"
  border="0"
  width="80%"
  style=""
  styleClass=""
  />

所有這些都是可選的。
3.6. 保存表的狀態

表新增了兩個屬性:state和stateAttr。state屬性參照State接口並能插接如何保存表的狀態的不同實現。

State藉口如下:

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

state屬性使用預設的四種狀態(default、notifyToDefault、persist和notifyToPersist)之一, 你也可以插接自己的實現。default狀態不維持任何狀態;persist狀態沒有任何參數傳入,將一直維持表的狀態; notifyToDefault狀態將一直維持表的狀態直到你傳入參數告訴它回到default狀態;notifyToPersist狀態 將一直維持當前狀態直到你傳入參數告訴它維持persisted狀態。

stateAttr爲指定參數提供了一條途徑,你也可以使用屬性文件在全局範圍內指定它。 爲了向後兼容,默認參數一直爲useSessionFilterSort。

如果你想state按照不同方式工作你只要實現State接口,然後使用TableTag的state屬性來指定實現類的 全路徑。

作爲一條首要規則當使用state屬性時,需要指定tableId。這是因爲state使用tableId爲名保存在session裏。 如果tableId不唯一,eXtremeTable將覆蓋另一個同名的內容。tableId默認值爲ec。
3.7. 其他屬性

爲了保持一致性,所有的顯示特性都命名爲showXXXX。他們包括showPagination、showStatusBar、 showTooltips、和showExports。

title屬性將在表的上方顯示標題,標題的位置根據使用的視圖不同而不同。當前默認視圖中標題位於表的上方 工具條的左邊。更詳細的信息請參考View。

你會發現還有一些屬性沒有被探討,因爲他們將在其他章探討。autoIncludeParameters在ParameterTag裏被探討; retrieveRowsCallback,sortRowsCallback和filterRowsCallback在Callbacks裏被探討。
3.8. 擴展屬性

大多數標籤包含一系列的固定屬性,這樣那些已經實現的功能能夠被使用。然而,eXtremeTable具有一種更具彈性的架構, 你可以添加自己的標籤屬性實現更多的定製工作。此外,eXtremeTable提供了非常清晰的鉤子(hooks)允許你得到那些定製的 標籤屬性來做一些你需要的工作。

通過addExtendedAttributes()方法將擴展屬性包含到eXtremeTable裏:

public void addExtendedAttributes(Table table);

如果方法被覆蓋TableTag將調用它。你需要做的就是擴展TableTag,覆蓋addExtendedAttributes()方法,然後添加自己 的屬性到表對象中。一個定製的TreeTag示例如下:

public class TreeTag extends TableTag {
    private String parentAttribute;
    private String identifier;

    public void setParentAttribute(String parentAttribute) {
        this.parentAttribute = parentAttribute;
    }

    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    public void addExtendedAttributes(Table table) {
        table.addAttribute(TableConstants.PARENT_ATTRIBUTE, TagUtils.evaluateExpressionAsString("parentAttribute",
                parentAttribute, this, pageContext));
        table.addAttribute(TableConstants.IDENTIFIER, TagUtils.evaluateExpressionAsString("identifier",
                identifier, this, pageContext));

        table.setFilterRowsCallback("org.extremecomponents.tree.ProcessTreeRowsCallback");
        table.setSortRowsCallback("org.extremecomponents.tree.ProcessTreeRowsCallback");
    }
}

現在你添加了屬性值到table對象。

另外,你也可以定製自己的標籤和自己的TLD文件。你不需要修改extremecomponents.tld文件。 你能象使用eXtremeTable裏的標籤一樣使用自己的標籤,除了使用你自己標籤的參照。假如你的標籤參照爲mycompany 並且標籤爲customTable,你可以像下面一樣使用他們:

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

Chapter 4. RowTag
4.1. 引言

RowTag用來定義表中的行。

一個簡單RowTag示例如下:

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

4.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類。
4.3. 樣式

RowTag關聯了很多樣式屬性:

<ec:row
  style=""
  styleClass=""
  highlightClass=""
  />

所有這些都是可選的。highlightClass設置行高亮顯示時的css類; style屬性定義行內聯的樣式;styleClass允許你定義一個行顯示的css類。
4.4. Javascript屬性

爲了便於你對於行數據進行動態交互處理,提供了onclick、onmouseover和 onmouseout屬性。

<ec:row
  οnclick=""
  οnmοuseοver=""
  οnmοuseοut=""
  />

4.5. 擴展屬性

大多數標籤包含一系列的固定屬性,這樣那些已經實現的功能能夠被使用。然而,eXtremeTable具有一種更具彈性的架構, 你可以添加自己的標籤屬性實現更多的定製工作。此外,eXtremeTable提供了非常清晰的鉤子(hooks)允許你得到那些定製的 標籤屬性來做一些你需要的工作。

通過addExtendedAttributes()方法將擴展屬性包含到eXtremeTable裏:

public void addExtendedAttributes(Row row);

Chapter 5. ColumnTag
5.1. 引言

ColumnTag用來定義表中的列。

示例President Bean:

public class President implements Serializable {
  private String firstName;
  private String lastName;

  public String getFirstName() {
    return firstName;
  }

  public void setFirstName(String firstName) {
    this.firstName = firstName;
  }

  public String getLastName() {
    return lastName;
  }

  public void setLastName(String lastName) {
    this.lastName = lastName;
  }
}

下例生成firstName和lastName列:

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

通過對TableTag的討論,已經知道列可以通過動態或精確的方式得到他們的值。 firstName列動態地取得相應的值,列找到當前的bean並調用相應的getFirstName()取得值。 lastName列明確地從當前bean取得值,它要求你自己取得相應的值。如下例:

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

從page範圍中取得名爲pres的bean並得到它對應的lastName屬性值。如果你正使用 Beans集合請確認具有對應的getter方法;如果使用Maps集合則不需要任何別的動作, eXtremeTable能夠通過屬性名從Map中得到對應的值。

提供這種可選取值方法的主要原因是使你能夠對其他類型的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>

切記bean中所有的屬性都是可訪問的,因此你甚至可以通過firstName屬性 來顯示下一頁。請注意firstName屬性是如何作爲URL字符串傳輸的。

<ec:table
  items="presidents"
  var="pres"
  action="${pageContext.request.contextPath}/presidents.run"
  />
  <ec:row>
    <ec:column property="lastName">
      <a href="http://goto.president.detail?firstName=${pageScope.pres.firstName}">
        ${pageScope.presidents.lastName}
      </a>
    </ec:column>
  </ec:row>
</ec:table>

我將不再在任何示例中強調pageScope。JSP標籤總是最先在pageScope中尋找任何對像, 因此我們總是能安全地返回正確的bean。
5.2. Cell

每一列總是被實現Cell接口的對象修飾,你可以認爲Cell是一個爲了html顯示或導出而返回格式化值的對象。 發行包包含的Cell有DisplayCell、DateCell、 NumberCell和RowCountCell。 DisplayCell是僅僅顯示列值的默認cell;DateCell使用parse屬性(可選)和format屬性來格式化對應的屬性值; NumberCell使用format屬性來格式化對應的屬性值;RowCountCell顯示當前行。

提示:爲了避免混亂並提高靈活性Cell接口已經被修改。而且對於區別 如何處理html和導出顯示值也不是很清晰。以前列值作爲html顯示,列的propertyValue作爲導出使用。 另外列值和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顯示存在明顯的區別。更重要的,需要返回字符串。列值和屬性值不再 需要設置。

DisplayCell是擴展AbstractCell的最簡單的Cell。AbstractCell定義 的虛擬方法getCellValue用來返回cell的值。雖然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);
}

現在你應該知道Cell是多麼簡單。只需通過實現Cell接口或擴展AbstractCell來定製你自己的Cell, 並設置列標籤的Cell屬性爲類的全路徑。例如: 如果你定製了一個名爲MyCell的Cell,那麼你可以像下面一樣使用它:

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

如果你改變列的數據,那麼過濾或排序可能沒有意義。切記我的意思是如果你人爲地改變數據, 而不是使用樣式對它進行包裝或作爲<a href>包含。 如果你的定製cell顯示數據的樹狀視圖,或者是一幅圖片, 那麼過濾和排序等一切邏輯操作都是沒有意義的。
5.3. Filter Cell

列的filterCell屬性控制過濾器如何顯示,它和cell屬性非常相像並且也是實現Cell接口。 已經定義了兩個過濾器cells:默認的和droplist。默認的是一個輸入框元素,除非你確信你需要使這列可以進行過濾, 否則你不需要做任何事。

你可以像下面一樣使用droplist過濾器Cell:

<ec:table
  items="presidents"
  action="${pageContext.request.contextPath}/presidents.run"
  >
  <ec:row>
    <ec:column property="status" filterCell="droplist"/>
  </ec:row>
</ec:table>

filterCell也允許你定義定製的過濾器,所有你必須做的就是實現Cell接口或者擴展AbstractCell, 並設置列標籤的Cell屬性爲類的全路徑。例如,如果你定製了一個名爲MyCell的Cell,那麼你可以像下面一樣使用它:

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

參閱Cell節瞭解如何創建你自己定製Cells的更多信息。
5.4. Header Cell

headerCell屬性控制headers如何顯示,它和cell屬性非常相像並且也是實現Cell接口。 默認header cell作爲文本顯示,包含排序邏輯。

headerCell也允許你定義定製的過濾器,所有你必須做的就是實現Cell接口或者擴展AbstractCell, 並設置列標籤的Cell屬性爲類的全路徑。例如,如果你定製了一個名爲MyCell的Cell,那麼你可以像下面一樣使用它:

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

參閱Cell節瞭解如何創建你自己定製Cells的更多信息。
5.5. 樣式

ColumnTag關聯了很多樣式屬性:

<ec:column
  width=""
  style=""
  styleClass=""
  headerStyle=""
  headerClass=""
  filterStyle=""
  filterClass=""
  />

所有這些都是可選的。style屬性定義列內聯的樣式;styleClass允許你定義一個列顯示的css類; headerClass屬性允許你改變header列的css類;filterClass屬性允許你改變filter列的css類。
5.6. 解析和格式化

解析和格式化屬性被用在日期和貨幣的顯示上。

和date交互的工作依賴於你的bean屬性是否是一個字符串或者是一個Date對象。 如果是一個字符串那麼你就需要確定parse屬性,parse屬性是按照模板定義來解析一個字符串爲 一個日期對象。如果bean中的屬性是日期型對象則不需要添加parse屬性。不論如何你都需要設置format屬性。 format屬性按你提供的模板對值進行格式化。

本示例中使用MM/dd/yyyy模板格式化日期型值。因爲bean中的born屬性值爲字符串,所以我們需要 使用parse屬性來將它轉換成日期型數值。

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

對於貨幣只需要設置format屬性:

<ec:column property="payroll" cell="currency" format="###,###,##0.00"/>

很多時候在extremeTable中,你使用同樣的模版來解析和格式化日期和貨幣值。 所以便利的方法是在你自己的extremecomponents.properties文件中定義解析和格式化屬性。 參閱Preferences章瞭解更多信息。
5.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>

5.8. Calc

列新增了兩個屬性: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並且不是線程安全的,因此不要定義任何類變量。
5.9. 允許和不允許視圖

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>

5.10. 其他屬性

title屬性用來爲header設定一個描述性的名稱。如果你不定義title那麼列將使用屬性名。 如果你不想顯示任何title,你只需要設置title屬性值爲一個空白(whitespace)。

<ec:table
  items="presidents"
  action="${pageContext.request.contextPath}/presidents.run"
  title="Presidents"
  >
  <ec:row>
    <ec:column property="firstName"/> //title shows as First Name
    <ec:column property="firstName" title="First Name"/> //title shows as First Name
    <ec:column property="firstName" title=" "/> //no title shows up
  </ec:row>
</ec:table>

5.11. 擴展屬性

大多數標籤包含一系列的固定屬性,這樣那些已經實現的功能能夠被使用。然而,eXtremeTable具有一種更具彈性的架構, 你可以添加自己的標籤屬性實現更多的定製工作。此外,eXtremeTable提供了非常清晰的鉤子(hooks)允許你得到那些定製的 標籤屬性來做一些你需要的工作。

通過addExtendedAttributes()方法將擴展屬性包含到eXtremeTable裏:

public void addExtendedAttributes(Column column);

如果方法被覆蓋ColumnTag將調用它。你需要做的就是擴展ColumnTag,覆蓋addExtendedAttributes()方法,然後添加自己 的屬性到列對象中。一個定製的CustomTag示例如下:

public class MyCustomTag extends ColumnTag {
  private String customAttributeOne;

  public String getCustomAttributeOne() {
    return customAttributeOne;
  }

  public void setCustomAttributeOne(String customAttributeOne) {
    this.customAttributeOne = customAttributeOne;
  }

  public void addExtendedAttributes(Column column) {
    column.addAttribute("customAttributeOne", customAttributeOne);
  }
}

現在你添加了屬性值到Column對象,現在你可以像下例一樣來定製cell:

public class MyCustomCell implements Cell {
  public String getHtmlDisplay(TableModel model, Column column) {
    Object customAttributeOne = column.getAttribute("customAttributeOne")
    String customAttributeOne = column.getAttributeAsString("customAttributeOne")
  }
}

另外,你也可以定製自己的標籤和自己的TLD文件。你不需要修改extremecomponents.tld文件。 你能象使用eXtremeTable裏的標籤一樣使用自己的標籤,除了使用你自己標籤的參照。假如你的標籤參照爲mycompany 並且標籤爲customColumn,你可以像下面一樣使用他們:

<ec:table
    items="presidents"
    action="${pageContext.request.contextPath}/public/demo/presidents.jsp"
    title="Presidents"
    >
  <ec:row>
    <mycompany:customColumn
               property="hello"
               cell="com.mycompany.cell.MyCustomCell"
               customAttributeOne="Hello World"/>
  </ec:row>
</ec:table>

Chapter 6. ParameterTag
6.1. 引言

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參數仍將被傳遞。
Chapter 7. ExportTag
7.1. 引言

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>

你可以通過指定view屬性來導出其他文件格式。eXtremeTable視圖實現View接口並是 可插接的。參閱View章瞭解更多信息。
7.2. 擴展屬性

大多數標籤包含一系列的固定屬性,這樣那些已經實現的功能能夠被使用。然而,eXtremeTable具有一種更具彈性的架構, 你可以添加自己的標籤屬性實現更多的定製工作。此外,eXtremeTable提供了非常清晰的鉤子(hooks)允許你得到那些定製的 標籤屬性來做一些你需要的工作。

通過addExtendedAttributes()方法將擴展屬性包含到eXtremeTable裏:

public void addExtendedAttributes(Export export);

如果方法被覆蓋ExportTag將調用它。你需要做的就是擴展ExportTag,覆蓋addExtendedAttributes()方法,然後添加自己 的屬性到導出對象中。

一個定製的ExportCsvTag示例如下:

public class ExportCsvTag extends ExportTag {
  private String delimiter;

  public String getDelimiter() {
        return delimiter;
  }

  public void setDelimiter(String delimiter) {
        this.delimiter = delimiter;
  }

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

現在你添加了屬性值到Export對象,下面是CsvView實現的一部分:

public class CsvView implements View {
  public void body(TableModel model, Column column) {
    Export export = model.getExportHandler().getCurrentExport();
  }
}

另外,你也可以定製自己的標籤和自己的TLD文件。你不需要修改extremecomponents.tld文件。 你能象使用eXtremeTable裏的標籤一樣使用自己的標籤,除了使用你自己標籤的參照。假如你的標籤參照爲mycompany 並且標籤爲customExport,你可以像下面一樣使用他們:

<ec:table
    items="presidents"
    action="${pageContext.request.contextPath}/public/demo/presidents.jsp"
    title="Presidents"
    >
  <mycompany:customExport fileName="presidents.txt" delimiter="|"/>
  ...
</ec:table>

Chapter 8. Callbacks
8.1. 引言

Callbacks被用於重新得到(retrieve)、過濾和排序行數據。eXtremeTable爲每個callback提供了一個定製實現。 首先,載入所有的元數據,元數據爲所有eXtremeTable標籤的所有屬性;接着在eXtremeTable的model中調用 execute方法。eXtremeTable使用execute方法決定如何通過調用每個callback的接口來重新得到、過濾和排序行數據。 這三個callback的接口是:RetrieveRowsCallback、FilterRowsCallback和SortRowsCallback。

callbacks爲singleton並且不是線程安全的,因此不要定義任何類變量。
8.2. RetrieveRowsCallback

RetrieveRowsCallback的默認實現在servlet範圍內尋找具有名稱和TableTag 的items屬性設置相同的Beans集合。爲了使用定製的callback,只要實現RetrieveRowsCallback接口, 然後使用retrieveRowsCallback屬性來指定實現類的全路徑:

<ec:table
  var="pres"
  action="${pageContext.request.contextPath}/presidents.run"
  retrieveRowsCallback="com.mycompany.callback.MyCustomCallback"
  />

RetrieveRowsCallback接口如下所示:

public interface RetrieveRowsCallback {
  public Collection retrieveRows(TableModel model) throws Exception;
}

只有一個方法需要實現,傳入TableModel並返回一個集合,集合爲Beans或Maps集合。 通過得到TableModel,就擁有了TableTag的所有元數據並能訪問Context。能夠訪問Context非常重要, 這意味着你訪問web容器的任何東西。
8.3. FilterRowsCallback

FilterRowsCallback的默認實現得到Beans集合,通過實現jakarta Predicate接口進行過濾, 過濾值從eXtremeTable的filter輸入框中取得。爲了使用定製的callback,只要實現FilterRowsCallback接口, 然後使用filterRowsCallback屬性來指定實現類的全路徑:

<ec:table
  var="pres"
  action="${pageContext.request.contextPath}/presidents.run"
  filterRowsCallback="com.mycompany.callback.MyCustomCallback"
  />

FilterRowsCallback接口如下所示:

public interface FilterRowsCallback {
  public Collection filterRows(TableModel model, Collection rows) throws Exception;
}

只有一個方法需要實現,傳入TableModel並返回一個集合。你只需像eXtremeTable對 每個callback的默認實現一樣來定製自己的callback。
8.4. SortRowsCallback

SortRowsCallback的默認實現得到Beans集合,使用jakarta BeanComparator進行排序, 排序值當用戶點擊列頭時取得。爲了使用定製的callback,只要實現SortRowsCallback接口, 然後使用sortRowsCallback屬性來指定實現類的全路徑:

<ec:table
  var="pres"
  action="${pageContext.request.contextPath}/presidents.run"
  sortRowsCallback="com.mycompany.callback.MyCustomCallback"
  />

SortRowsCallback接口如下所示:

public interface SortRowsCallback {
  public Collection sortRows(TableModel model, Collection rows) throws Exception;
}

只有一個方法需要實現,傳入TableModel並返回一個集合。你只需像eXtremeTable對 每個callback的默認實現一樣來定製自己的callback。
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

現在僅支持英語和德語。如果你使用其他語言的話,並能提供相應的翻譯的話我將不勝感激。你可以通過 [email protected]發送給我。

譯者注:我已經提供了中文和日文的資源文件。
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. 
Name 	Description
action 	The URI that will be called when the filter, sort and pagination is used.
autoIncludeParameters 	Specify whether or not to automatically include the parameters, as hidden inputs, passed into the JSP.
border 	The table border attribute. The default is 0.
cellpadding 	The table cellpadding attribute. The default is 0.
cellspacing 	The table cellspacing attribute. The default is 0.
filterable 	Specify whether or not the table is filterable. Boolean value with the default being true.
filterRowsCallback 	A 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.
form 	The reference to a surrounding form element.
imagePath 	The path to find the images. For example imagePath=/extremesite/images/*.png is saying look in the image directory for the .png images.
intercept 	A fully qualified class name to a custom InterceptTable implementation. Could also be a named type in the preferences. Used to add table attributes.
items 	Reference the collection that will be retrieved.
locale 	The locale for this table. For example fr_FR is used for the French translation.
method 	Used to invoke the table action using a POST or GET.
onsubmit 	The javascript onsubmit action for the table.
retrieveRowsCallback 	A 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.
rowsDisplayed 	The number of rows to display in the table.
scope 	The scope (page, request, session, or application) to find the Collection of beans or Collection of Maps defined by the collection attribute.
showPagination 	Specify whether or not the table should use pagination. Boolean value with the default being true.
showExports 	Specify whether or not the table should use the exports. Boolean value with the default being true.
showStatusBar 	Specify whether or not the table should use the status bar. Boolean value with the default being true.
showTooltips 	Specify whether or not to show the tooltips. Boolean value with the default being true.
sortRowsCallback 	A 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.
sortable 	Specify whether or not the table is sortable. Boolean value with the default being true.
state 	The table state to use when returning to a table. Acceptable values are default, notifyToDefault, persist, notifyToPersist.
stateAttr 	The table attribute used to invoke the state change of the table.
style 	The css inline style sheet.
styleClass 	The css class style sheet.
tableId 	The unique identifier for the table.
theme 	The theme to style the table. The default is eXtremeTable.
title 	The title of the table. The title will display above the table.
var 	The name of the variable to hold the current row bean.
view 	Generates the output. The default is the HtmlView to generate the HTML. Also used by the exports to generate XLS-FO, POI, and CSV.
width 	Width of the table.
16.2. RowTag

Table 16.2. 
Name 	Description
highlightClass 	The css class style sheet when highlighting rows.
highlightRow 	Used to turn the highlight feature on and off. Acceptable values are true or false. The default is false.
intercept 	A 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.
onclick 	The javascript onclick action
onmouseout 	The javascript onmouseout action
onmouseover 	The javascript onmouseover action
style 	The css inline style sheet.
styleClass 	The css class style sheet.
16.3. ColumnTag

Table 16.3. 
Name 	Description
alias 	Used to uniquely identify the column when the same property is used for more than one column.
calc 	A 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.
calcTitle 	The title of the calc.
cell 	Display 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.
escapeAutoFormat 	Specify whether auto format of value will be skipped. False by default, and is only effective if autoformatting is implement in the view.
filterable 	Specify 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.
filterCell 	Displays 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.
filterClass 	The css class style sheet used to define what the table filter column looks like.
filterStyle 	The css class style sheet to use for the filter column.
format 	The format to use for the cell. For instance if used with a date cell then the format can be MM/dd/yyyy.
headerCell 	Display for the header column. The default is header. The cell can also be a fully qualified class name to a custom cell.
headerClass 	The css class style sheet used to define what the table header column looks like.
headerStyle 	The css class style sheet to use for the header column.
intercept 	A 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.
parse 	Used if the format needs to be interpreted. For instance, a date needs to be parsed in the specific format, such as MM-dd-yyyy.
property 	The bean attribute to use for the column.
sortable 	Specify 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.
style 	The css inline style sheet.
styleClass 	The css class style sheet.
title 	The 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.
value 	The 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.
viewsAllowed 	The comma separated list of views that this column will be used in.
viewsDenied 	The comma separated list of views that this column will not be used in.
width 	Specify the column width.
16.4. ExportTag

Table 16.4. 
Name 	Description
fileName 	The name of the export file.
imageName 	The image name.
intercept 	A 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.
view 	A 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.
viewResolver 	A 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.
text 	The text for the export view.
tooltip 	The tooltip that shows up when you mouseover the export image.
16.5. ExportXlsTag

Table 16.5. 
Name 	Description
fileName 	The name of the export file.
imageName 	The image name.
intercept 	A 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.
view 	A 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.
viewResolver 	A 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.
text 	The text for the export view.
tooltip 	The tooltip that shows up when you mouseover the export image.
16.6. ExportCsvTag

Table 16.6. 
Name 	Description
delimiter 	What to use as the file delimiter. The default is a comma.
fileName 	The name of the export file.
imageName 	The image name.
intercept 	A 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.
view 	A 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.
viewResolver 	A 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.
text 	The text for the export view.
tooltip 	The tooltip that shows up when you mouseover the export image.
16.7. ExportPdfTag

Table 16.7. 
Name 	Description
headerBackgroundColor 	The background color on the header column.
headerColor 	The font color for the header column.
headerTitle 	The title displayed at the top of the page.
fileName 	The name of the export file.
imageName 	The image name.
intercept 	A 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.
view 	A 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.
viewResolver 	A 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.
text 	The text for the export view.
tooltip 	The tooltip that shows up when you mouseover the export image.
16.8. ColumnsTag

Table 16.8. 
Name 	Description
autoGenerateColumns 	A 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

發佈了16 篇原創文章 · 獲贊 26 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章