<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    空間站

    北極心空

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      15 Posts :: 393 Stories :: 160 Comments :: 0 Trackbacks

    eXtremeComponents

    參考文檔

    Jeff Johnston

    版本1.0.0

    本文檔允許在遵守以下兩條原則的條件下被使用和傳播: 1)不能憑借本文檔索取任何費(fèi)用 2)以任何方式(印刷物或電子版)使用和傳播時(shí)本文檔時(shí),必須包含本版權(quán)申明

    (更新中...)


    Table of Contents

    前言
    1. 配置
    1.1. 先決條件
    1.2. 安裝
    1.3. 導(dǎo)出過濾器(可選)
    1.4. 安裝測試
    2. 概述
    2.1. 引言
    3. TableTag
    3.1. 引言
    3.2. 顯示圖片
    3.3. 過濾、排序和動(dòng)作(Action)
    3.4. 設(shè)定每頁顯示行數(shù)
    3.5. 樣式
    3.6. 保存表的狀態(tài)
    3.7. 其他屬性
    3.8. 擴(kuò)展屬性
    4. RowTag
    4.1. 引言
    4.2. 高亮顯示行
    4.3. 樣式
    4.4. Javascript屬性
    4.5. 擴(kuò)展屬性
    5. ColumnTag
    5.1. 引言
    5.2. Cell
    5.3. Filter Cell
    5.4. Header Cell
    5.5. 樣式
    5.6. 解析和格式化
    5.7. 過濾和排序
    5.8. Calc
    5.9. 允許和不允許視圖
    5.10. 其他屬性
    5.11. 擴(kuò)展屬性
    6. ParameterTag
    6.1. 引言
    7. ExportTag
    7.1. 引言
    7.2. 擴(kuò)展屬性
    8. Callbacks
    8.1. 引言
    8.2. RetrieveRowsCallback
    8.3. FilterRowsCallback
    8.4. SortRowsCallback
    9. 視圖
    9.1. 引言
    9.2. 表視圖
    9.3. 導(dǎo)出視圖
    10. Preferences
    10.1. 引言
    10.2. TableTag
    10.3. ColumnTag
    10.4. Advanced Techniques
    11. Messages
    11.1. 資源綁定
    11.2. 全局資源
    11.3. TableTag
    11.4. ColumnTag
    12. Limit
    12.1. Limit指南
    12.2. 創(chuàng)建Limit
    12.3. Filter和Sort屬性
    12.4. 設(shè)置頁和行屬性
    12.5. Setup
    13. AutoGenerateColumns
    13.1. 引言
    13.2. ColumnsTag
    14. Utilities
    14.1. 引言
    14.2. HtmlBuilder
    15. 1.0.1-M4升級(jí)說明
    15.1. 變更概述
    15.1.1. HtmlView
    15.1.2. Cell
    15.1.3. RowTag
    15.1.4. AutoGenerateColumns
    15.1.5. Extended Attributes
    15.1.6. TableTag的collection屬性
    15.1.7. BaseModel
    15.1.8. Properties和ResourceBundle
    15.1.9. pageContext
    15.1.10. Limit和LimitFactory
    15.1.11. TableTag的saveFilterSort屬性
    15.1.12. ColumnTag的showTotal屬性
    15.1.13. Image名
    15.1.14. FormTag / InputTag Deprecated
    15.1.15. RetrieveRowsCallbacks、FilterRowsCallback、SortRowsCallback
    16. Tag Attributes
    16.1. TableTag
    16.2. RowTag
    16.3. ColumnTag
    16.4. ExportTag
    16.5. ExportXlsTag
    16.6. ExportCsvTag
    16.7. ExportPdfTag
    16.8. ColumnsTag
    16.9. ParameterTag

    前言

    eXtremeComponents是一系列提供高級(jí)顯示的開源JSP定制標(biāo)簽。當(dāng)前的包含 的組件為eXtremeTable,用于以表的形式顯示數(shù)據(jù)。

    本文檔處于更新中。大部分章節(jié)我將僅僅描述如何使用eXtremeTable。當(dāng)然, 為了使程序高效并具有更高的靈活性,源代碼被再三重構(gòu)。隨后, 我認(rèn)為闡述一下如 何做設(shè)計(jì)決定是值得的。我希望大家能知道使用extremeTable是多么容易,并且所 有的東西都是可配置。如果你有任何的要求和建議, 請及時(shí)通過論壇或者 extremecomponents@gmail.com和我聯(lián)系。

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

    譯者注:如果大家有什么疑問和建議,可以通過xplucky@gmail.com和我聯(lián)系。

    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導(dǎo)出需要的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導(dǎo)出需要的Jars:

    • minimum jars (above)

    • poi-2.5.1.jar

    1.2. 安裝

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

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

    • extremecomponents.jar

    • extremecomponents.tld

    • extremecomponents.css

    • 默認(rèn)的一組圖片

    • 源代碼

    • test.jsp (用于確認(rèn)安裝是否正確)

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

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

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

    隨后,你需要向下面一樣在你的JSP里把eXtremeTable包含進(jìn)來:

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

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

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

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

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

    1.3. 導(dǎo)出過濾器(可選)

    為了使導(dǎo)出功能有效,你需要設(shè)置導(dǎo)出過濾器。這是一個(gè)僅用于導(dǎo)出功能的可選配置。

    如下所示在/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>

    過濾器還有一個(gè)可選的初始化參數(shù),用于決定什么時(shí)候生成報(bào)頭(headers)。我發(fā)現(xiàn)大多數(shù)的servlet容器 傾向于在調(diào)用過濾器的doFilter()方法后才設(shè)置響應(yīng)報(bào)頭(response headers)。然而,一些servlet容器只有在 調(diào)用過濾器的doFilter()方法前設(shè)置響應(yīng)報(bào)頭,過濾器才能正常工作。默認(rèn)的方法是調(diào)用過濾器的doFilter()方法后 設(shè)置響應(yīng)報(bào)頭,你可以通過使用responseHeadersSetBeforeDoFilter這個(gè)初始化參數(shù)調(diào)整它。

    <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擴(kuò)展了正常的 sitemesh的PageFilter,它使得正在進(jìn)行導(dǎo)出的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. 安裝測試

    使用發(fā)行包的test.jsp來測試安裝。將test.jsp拷貝到web應(yīng)用的最頂層, 默認(rèn)的圖片文件在 /images/table/子目錄下。為了測試,創(chuàng)建相應(yīng)的目錄并將拷貝所有需要的圖片。所有工作都完成后,你可以在瀏覽 器里運(yùn)行test.jsp了。

    提示: 我不提倡在JSP里使用腳本(scriplets),但為了不用使用框架而能進(jìn)行快速測試,在test.jsp 使用腳本是唯一的辦法。

    Chapter 2. 概述

    2.1. 引言

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

    集合里的Beans是pojo,如果使用maps那么它就是鍵值對。你可以認(rèn)為每一個(gè)bean就是表中的一行數(shù)據(jù)。 在接下來的文檔中,我將使用Beans集合來代替這兩種集合。

    實(shí)際表使用的最小語法如下所示:

    <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的一個(gè)典型定義。通過這些定義,你將得到格式化的列和頁頭,工具欄的所有 特性也能很好工作。

    Chapter 3. TableTag

    3.1. 引言

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

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

    現(xiàn)在你可以構(gòu)造表了:

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

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

    從一列中明確取得值非常有用,但是你需要理解表是如何構(gòu)造行的。為了構(gòu)造行,表需要對所有行進(jìn)行 rowsDisplayed屬性設(shè)定次數(shù)的迭代。每次迭代都從Beans里取得下一個(gè)bean并使用var屬性設(shè)定的名稱傳入page 范圍。也可以說每次迭代你都訪問的是集合中當(dāng)前行對應(yīng)的bean。

    3.2. 顯示圖片

    為了顯示圖片需要設(shè)置imagePath屬性:

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

    eXtremeTable將找到一個(gè)目錄下的所有圖片并使用特殊的語法來定義他們是那類圖片。 本示例中所有的圖片都直接保存在web上下文的images目錄下。*.gif使eXtremeTable知道所 有的圖片都是GIF格式的。在我們討論preferences后,你將發(fā)現(xiàn)你可以你可以通過在 extremecomponents.properties文件中設(shè)定這個(gè)屬性,而不用再整個(gè)應(yīng)用的每個(gè)eXtremeTable 中包含它。

    3.3. 過濾、排序和動(dòng)作(Action)

    eXtremeTable內(nèi)嵌了過濾和排序功能,你只需要決定是否需要使用他們。你要使用的屬性是 filterable和sortable,他們都是布爾值并且默認(rèn)值是true。默認(rèn)的所有特性都有效,你可以按照 需要來關(guān)掉一些特性。比如,如果你不想使用排序或過濾你可以把他們的屬性設(shè)為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>

    如果你仍不確信,你可以來驗(yàn)證他們。首先,設(shè)置filterable和sortable為true,你將看到 eXtremeTable允許你輸入關(guān)鍵詞來過濾結(jié)果集,它也允許你通過在頁頭(header)上滾動(dòng)鼠標(biāo)來排序。 然后,設(shè)置filterable和sortable為fale,你將發(fā)現(xiàn)所有這些特性都不允許使用。

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

    3.4. 設(shè)定每頁顯示行數(shù)

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

    提示:如果你想在一頁中顯示所有行,只需要設(shè)置showPagination為false。

    3.5. 樣式

    TableTag關(guān)聯(lián)了很多樣式屬性:

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

    所有這些都是可選的。

    3.6. 保存表的狀態(tài)

    表新增了兩個(gè)屬性:state和stateAttr。state屬性參照State接口并能插接如何保存表的狀態(tài)的不同實(shí)現(xiàn)。

    State借口如下:

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

    state屬性使用預(yù)設(shè)的四種狀態(tài)(default、notifyToDefault、persist和notifyToPersist)之一, 你也可以插接自己的實(shí)現(xiàn)。default狀態(tài)不維持任何狀態(tài);persist狀態(tài)沒有任何參數(shù)傳入,將一直維持表的狀態(tài); notifyToDefault狀態(tài)將一直維持表的狀態(tài)直到你傳入?yún)?shù)告訴它回到default狀態(tài);notifyToPersist狀態(tài) 將一直維持當(dāng)前狀態(tài)直到你傳入?yún)?shù)告訴它維持persisted狀態(tài)。

    stateAttr為指定參數(shù)提供了一條途徑,你也可以使用屬性文件在全局范圍內(nèi)指定它。 為了向后兼容,默認(rèn)參數(shù)一直為useSessionFilterSort。

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

    作為一條首要規(guī)則當(dāng)使用state屬性時(shí),需要指定tableId。這是因?yàn)閟tate使用tableId為名保存在session里。 如果tableId不唯一,eXtremeTable將覆蓋另一個(gè)同名的內(nèi)容。tableId默認(rèn)值為ec。

    3.7. 其他屬性

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

    title屬性將在表的上方顯示標(biāo)題,標(biāo)題的位置根據(jù)使用的視圖不同而不同。當(dāng)前默認(rèn)視圖中標(biāo)題位于表的上方 工具條的左邊。更詳細(xì)的信息請參考View。

    你會(huì)發(fā)現(xiàn)還有一些屬性沒有被探討,因?yàn)樗麄儗⒃谄渌绿接憽utoIncludeParameters在ParameterTag里被探討; retrieveRowsCallback,sortRowsCallback和filterRowsCallback在Callbacks里被探討。

    3.8. 擴(kuò)展屬性

    大多數(shù)標(biāo)簽包含一系列的固定屬性,這樣那些已經(jīng)實(shí)現(xiàn)的功能能夠被使用。然而,eXtremeTable具有一種更具彈性的架構(gòu), 你可以添加自己的標(biāo)簽屬性實(shí)現(xiàn)更多的定制工作。此外,eXtremeTable提供了非常清晰的鉤子(hooks)允許你得到那些定制的 標(biāo)簽屬性來做一些你需要的工作。

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

    public void addExtendedAttributes(Table table);

    如果方法被覆蓋TableTag將調(diào)用它。你需要做的就是擴(kuò)展TableTag,覆蓋addExtendedAttributes()方法,然后添加自己 的屬性到表對象中。一個(gè)定制的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");
    }
    }

    現(xiàn)在你添加了屬性值到table對象。

    另外,你也可以定制自己的標(biāo)簽和自己的TLD文件。你不需要修改extremecomponents.tld文件。 你能象使用eXtremeTable里的標(biāo)簽一樣使用自己的標(biāo)簽,除了使用你自己標(biāo)簽的參照。假如你的標(biāo)簽參照為mycompany 并且標(biāo)簽為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用來定義表中的行。

    一個(gè)簡單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屬性可以設(shè)置行的高亮顯示,它的值為true或false,默認(rèn)值為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>

    設(shè)置highlightRow屬性后,它將插入設(shè)置行css類的javascript腳本,默認(rèn)的css 類為highlight。你可以使用highlightClass來使用定制的css類。

    4.3. 樣式

    RowTag關(guān)聯(lián)了很多樣式屬性:

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

    所有這些都是可選的。highlightClass設(shè)置行高亮顯示時(shí)的css類; style屬性定義行內(nèi)聯(lián)的樣式;styleClass允許你定義一個(gè)行顯示的css類。

    4.4. Javascript屬性

    為了便于你對于行數(shù)據(jù)進(jìn)行動(dòng)態(tài)交互處理,提供了onclick、onmouseover和 onmouseout屬性。

    <ec:row
    onclick=""
    onmouseover=""
    onmouseout=""
    />

    4.5. 擴(kuò)展屬性

    大多數(shù)標(biāo)簽包含一系列的固定屬性,這樣那些已經(jīng)實(shí)現(xiàn)的功能能夠被使用。然而,eXtremeTable具有一種更具彈性的架構(gòu), 你可以添加自己的標(biāo)簽屬性實(shí)現(xiàn)更多的定制工作。此外,eXtremeTable提供了非常清晰的鉤子(hooks)允許你得到那些定制的 標(biāo)簽屬性來做一些你需要的工作。

    通過addExtendedAttributes()方法將擴(kuò)展屬性包含到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的討論,已經(jīng)知道列可以通過動(dòng)態(tài)或精確的方式得到他們的值。 firstName列動(dòng)態(tài)地取得相應(yīng)的值,列找到當(dāng)前的bean并調(diào)用相應(yīng)的getFirstName()取得值。 lastName列明確地從當(dāng)前bean取得值,它要求你自己取得相應(yīng)的值。如下例:

    <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并得到它對應(yīng)的lastName屬性值。如果你正使用 Beans集合請確認(rèn)具有對應(yīng)的getter方法;如果使用Maps集合則不需要任何別的動(dòng)作, eXtremeTable能夠通過屬性名從Map中得到對應(yīng)的值。

    提供這種可選取值方法的主要原因是使你能夠?qū)ζ渌愋偷膆tml標(biāo)簽提供動(dòng)作支持,例如顯示 一幅圖片或者通過定義href使該列成為到其它頁的一個(gè)鏈接。

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

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

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

    我將不再在任何示例中強(qiáng)調(diào)pageScope。JSP標(biāo)簽總是最先在pageScope中尋找任何對像, 因此我們總是能安全地返回正確的bean。

    5.2. Cell

    每一列總是被實(shí)現(xiàn)Cell接口的對象修飾,你可以認(rèn)為Cell是一個(gè)為了html顯示或?qū)С龆祷馗袷交档膶ο蟆?發(fā)行包包含的Cell有DisplayCell、DateCell、 NumberCell和RowCountCell。 DisplayCell是僅僅顯示列值的默認(rèn)cell;DateCell使用parse屬性(可選)和format屬性來格式化對應(yīng)的屬性值; NumberCell使用format屬性來格式化對應(yīng)的屬性值;RowCountCell顯示當(dāng)前行。

    提示:為了避免混亂并提高靈活性Cell接口已經(jīng)被修改。而且對于區(qū)別 如何處理html和導(dǎo)出顯示值也不是很清晰。以前列值作為html顯示,列的propertyValue作為導(dǎo)出使用。 另外列值和propertyValue已經(jīng)重寫,他們以前在view中是不能被訪問的。

    cell現(xiàn)在是singleton并且不再線程安全,改變的原因是為了Cell接口能更簡單地被使用。 init()和destroy()方法作為singleton更靈活但是處于一種混亂的狀態(tài)。

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

    現(xiàn)在得到導(dǎo)出和html顯示存在明顯的區(qū)別。更重要的,需要返回字符串。列值和屬性值不再 需要設(shè)置。

    DisplayCell是擴(kuò)展AbstractCell的最簡單的Cell。AbstractCell定義 的虛擬方法getCellValue用來返回cell的值。雖然AbstractCell在一些情況下是有用的, 但更多情況下只需要直接實(shí)現(xiàn)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);
    }

    現(xiàn)在你應(yīng)該知道Cell是多么簡單。只需通過實(shí)現(xiàn)Cell接口或擴(kuò)展AbstractCell來定制你自己的Cell, 并設(shè)置列標(biāo)簽的Cell屬性為類的全路徑。例如: 如果你定制了一個(gè)名為MyCell的Cell,那么你可以像下面一樣使用它:

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

    如果你改變列的數(shù)據(jù),那么過濾或排序可能沒有意義。切記我的意思是如果你人為地改變數(shù)據(jù), 而不是使用樣式對它進(jìn)行包裝或作為<a href>包含。 如果你的定制cell顯示數(shù)據(jù)的樹狀視圖,或者是一幅圖片, 那么過濾和排序等一切邏輯操作都是沒有意義的。

    5.3. Filter Cell

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

    你可以像下面一樣使用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也允許你定義定制的過濾器,所有你必須做的就是實(shí)現(xiàn)Cell接口或者擴(kuò)展AbstractCell, 并設(shè)置列標(biāo)簽的Cell屬性為類的全路徑。例如,如果你定制了一個(gè)名為MyCell的Cell,那么你可以像下面一樣使用它:

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

    參閱Cell節(jié)了解如何創(chuàng)建你自己定制Cells的更多信息。

    5.4. Header Cell

    headerCell屬性控制headers如何顯示,它和cell屬性非常相像并且也是實(shí)現(xiàn)Cell接口。 默認(rèn)header cell作為文本顯示,包含排序邏輯。

    headerCell也允許你定義定制的過濾器,所有你必須做的就是實(shí)現(xiàn)Cell接口或者擴(kuò)展AbstractCell, 并設(shè)置列標(biāo)簽的Cell屬性為類的全路徑。例如,如果你定制了一個(gè)名為MyCell的Cell,那么你可以像下面一樣使用它:

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

    參閱Cell節(jié)了解如何創(chuàng)建你自己定制Cells的更多信息。

    5.5. 樣式

    ColumnTag關(guān)聯(lián)了很多樣式屬性:

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

    所有這些都是可選的。style屬性定義列內(nèi)聯(lián)的樣式;styleClass允許你定義一個(gè)列顯示的css類; headerClass屬性允許你改變header列的css類;filterClass屬性允許你改變filter列的css類。

    5.6. 解析和格式化

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

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

    本示例中使用MM/dd/yyyy模板格式化日期型值。因?yàn)閎ean中的born屬性值為字符串,所以我們需要 使用parse屬性來將它轉(zhuǎn)換成日期型數(shù)值。

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

    對于貨幣只需要設(shè)置format屬性:

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

    很多時(shí)候在extremeTable中,你使用同樣的模版來解析和格式化日期和貨幣值。 所以便利的方法是在你自己的extremecomponents.properties文件中定義解析和格式化屬性。 參閱Preferences章了解更多信息。

    5.7. 過濾和排序

    你可能記得在TableTag中看見過filterable和sortable屬性,ColumnTag中也有相同的屬性。 列的filterable和sortable屬性將覆蓋表的filterable和sortable屬性設(shè)置。當(dāng)你需要除了對表中的一、兩列之外的 所有列進(jìn)行過濾和排序時(shí),十分便利。

    <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

    列新增了兩個(gè)屬性:calc和calcTitle:

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

    calc屬性實(shí)現(xiàn)具有唯一方法的Calc接口:

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

    它傳入model和column,并返回一個(gè)Number型的值。默認(rèn)的實(shí)現(xiàn)為總計(jì)和平均值。

    為了使用定制的Calc,只需要使用ColumnTag的calc屬性來指定實(shí)現(xiàn)Calc接口的實(shí)現(xiàn)類的 全路徑。

    Calc為singleton并且不是線程安全的,因此不要定義任何類變量。

    5.9. 允許和不允許視圖

    viewsAllowed屬性制定類允許使用的視圖。視圖包括:html、pdf、xls、csv,以及任何定制的視圖。 如果你指定一個(gè)或幾個(gè)視圖,那么列僅能使用這些指定的視圖。例如:你指定viewsAllowed="pdf",這意味著 這列只允許PDF導(dǎo)出,而不能進(jìn)行其他格式的導(dǎo)出或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,以及任何定制的視圖。 如果你指定一個(gè)或幾個(gè)視圖,那么列僅這些指定的視圖不能被使用。例如:你指定viewsDenied="html",這意味著 這列不允許使用html試圖,但能進(jìn)行任何形式的導(dǎo)出。

    <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設(shè)定一個(gè)描述性的名稱。如果你不定義title那么列將使用屬性名。 如果你不想顯示任何title,你只需要設(shè)置title屬性值為一個(gè)空白(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. 擴(kuò)展屬性

    大多數(shù)標(biāo)簽包含一系列的固定屬性,這樣那些已經(jīng)實(shí)現(xiàn)的功能能夠被使用。然而,eXtremeTable具有一種更具彈性的架構(gòu), 你可以添加自己的標(biāo)簽屬性實(shí)現(xiàn)更多的定制工作。此外,eXtremeTable提供了非常清晰的鉤子(hooks)允許你得到那些定制的 標(biāo)簽屬性來做一些你需要的工作。

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

    public void addExtendedAttributes(Column column);

    如果方法被覆蓋ColumnTag將調(diào)用它。你需要做的就是擴(kuò)展ColumnTag,覆蓋addExtendedAttributes()方法,然后添加自己 的屬性到列對象中。一個(gè)定制的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);
    }
    }

    現(xiàn)在你添加了屬性值到Column對象,現(xiàn)在你可以像下例一樣來定制cell:

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

    另外,你也可以定制自己的標(biāo)簽和自己的TLD文件。你不需要修改extremecomponents.tld文件。 你能象使用eXtremeTable里的標(biāo)簽一樣使用自己的標(biāo)簽,除了使用你自己標(biāo)簽的參照。假如你的標(biāo)簽參照為mycompany 并且標(biāo)簽為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能夠指定是否處理所有的參數(shù)。默認(rèn)為處理所有的參數(shù),這意味著當(dāng)你進(jìn)行 過濾、排序、分頁時(shí),所有的參數(shù)都被eXtremeTable保存并傳到JSP中。通常這是你需要的功能, 然而,有時(shí)候你需要只允許一些特定的參數(shù)保存到eXtremeTable中。我喜歡把它看作鎖定extremeTable, 可以通過設(shè)置表的autoIncludeParameters屬性值為false來到達(dá)目的:

    <ec:table
    items="presidents"
    action="${pageContext.request.contextPath}/presidents.run"
    autoIncludeParameters=”false”
    >
    ...
    </ec:table>

    甚至當(dāng)表被鎖定時(shí),你仍然可以通過簡單地使用parameter標(biāo)簽來包含一些你想使用的參數(shù)。下例 包含了foo參數(shù):

    <ec:table
    items="presidents"
    action="${pageContext.request.contextPath}/presidents.run"
    autoIncludeParameters=”false”
    >
    <ec:parameter name=”foo” value=”${param.foo}”/>
    ...
    </ec:table>

    現(xiàn)在所有的eXtremeTable參數(shù)都被鎖定。但過濾、排序和翻頁時(shí),foo參數(shù)仍將被傳遞。

    Chapter 7. ExportTag

    7.1. 引言

    eXtremeTable具有導(dǎo)出不同格式文件的功能,導(dǎo)出的數(shù)據(jù)為過濾和排序后的所有結(jié)果集, 分頁不會(huì)影響返回的結(jié)果集。換句話說,如果表數(shù)據(jù)分多頁顯示,那么所有頁的數(shù)據(jù)都將被導(dǎo)出。 導(dǎo)出的格式為Microsoft Excel (OpenOffice Calc)、PDF和CSV。

    使用ExportXlsTag導(dǎo)出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導(dǎo)出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導(dǎo)出CSV。當(dāng)使用CSV導(dǎo)出是默認(rèn)的分隔符為‘,’(comma)。你可以使用 delimiter屬性來指定為其他的符號(hào)。下面為指定‘|’(pipe)為CSV分隔符的示例:

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

    你可以通過指定view屬性來導(dǎo)出其他文件格式。eXtremeTable視圖實(shí)現(xiàn)View接口并是 可插接的。參閱View章了解更多信息。

    7.2. 擴(kuò)展屬性

    大多數(shù)標(biāo)簽包含一系列的固定屬性,這樣那些已經(jīng)實(shí)現(xiàn)的功能能夠被使用。然而,eXtremeTable具有一種更具彈性的架構(gòu), 你可以添加自己的標(biāo)簽屬性實(shí)現(xiàn)更多的定制工作。此外,eXtremeTable提供了非常清晰的鉤子(hooks)允許你得到那些定制的 標(biāo)簽屬性來做一些你需要的工作。

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

    public void addExtendedAttributes(Export export);

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

    一個(gè)定制的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());
    }
    }

    現(xiàn)在你添加了屬性值到Export對象,下面是CsvView實(shí)現(xiàn)的一部分:

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

    另外,你也可以定制自己的標(biāo)簽和自己的TLD文件。你不需要修改extremecomponents.tld文件。 你能象使用eXtremeTable里的標(biāo)簽一樣使用自己的標(biāo)簽,除了使用你自己標(biāo)簽的參照。假如你的標(biāo)簽參照為mycompany 并且標(biāo)簽為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)、過濾和排序行數(shù)據(jù)。eXtremeTable為每個(gè)callback提供了一個(gè)定制實(shí)現(xiàn)。 首先,載入所有的元數(shù)據(jù),元數(shù)據(jù)為所有eXtremeTable標(biāo)簽的所有屬性;接著在eXtremeTable的model中調(diào)用 execute方法。eXtremeTable使用execute方法決定如何通過調(diào)用每個(gè)callback的接口來重新得到、過濾和排序行數(shù)據(jù)。 這三個(gè)callback的接口是:RetrieveRowsCallback、FilterRowsCallback和SortRowsCallback。

    callbacks為singleton并且不是線程安全的,因此不要定義任何類變量。

    8.2. RetrieveRowsCallback

    RetrieveRowsCallback的默認(rèn)實(shí)現(xiàn)在servlet范圍內(nèi)尋找具有名稱和TableTag 的items屬性設(shè)置相同的Beans集合。為了使用定制的callback,只要實(shí)現(xiàn)RetrieveRowsCallback接口, 然后使用retrieveRowsCallback屬性來指定實(shí)現(xiàn)類的全路徑:

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

    只有一個(gè)方法需要實(shí)現(xiàn),傳入TableModel并返回一個(gè)集合,集合為Beans或Maps集合。 通過得到TableModel,就擁有了TableTag的所有元數(shù)據(jù)并能訪問Context。能夠訪問Context非常重要, 這意味著你訪問web容器的任何東西。

    8.3. FilterRowsCallback

    FilterRowsCallback的默認(rèn)實(shí)現(xiàn)得到Beans集合,通過實(shí)現(xiàn)jakarta Predicate接口進(jìn)行過濾, 過濾值從eXtremeTable的filter輸入框中取得。為了使用定制的callback,只要實(shí)現(xiàn)FilterRowsCallback接口, 然后使用filterRowsCallback屬性來指定實(shí)現(xiàn)類的全路徑:

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

    只有一個(gè)方法需要實(shí)現(xiàn),傳入TableModel并返回一個(gè)集合。你只需像eXtremeTable對 每個(gè)callback的默認(rèn)實(shí)現(xiàn)一樣來定制自己的callback。

    8.4. SortRowsCallback

    SortRowsCallback的默認(rèn)實(shí)現(xiàn)得到Beans集合,使用jakarta BeanComparator進(jìn)行排序, 排序值當(dāng)用戶點(diǎn)擊列頭時(shí)取得。為了使用定制的callback,只要實(shí)現(xiàn)SortRowsCallback接口, 然后使用sortRowsCallback屬性來指定實(shí)現(xiàn)類的全路徑:

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

    只有一個(gè)方法需要實(shí)現(xiàn),傳入TableModel并返回一個(gè)集合。你只需像eXtremeTable對 每個(gè)callback的默認(rèn)實(shí)現(xiàn)一樣來定制自己的callback。

    Chapter 9. 視圖

    9.1. 引言

    eXtremeTable里視圖是可插接的,這意味著html很容易改變,或者一類新的導(dǎo)出能夠被實(shí)現(xiàn)。 所有需要做的就是實(shí)現(xiàn)View接口并在TableTag或ExportTag中設(shè)置view屬性。首先,讓我們看一下View接口:

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

    實(shí)現(xiàn)View接口的類有三次插入內(nèi)容的機(jī)會(huì)。beforeBody()方法會(huì)被立刻調(diào)用; body()方法在每一行的每一列處理的時(shí)候調(diào)用;afterBody()方法是被eXtremeTable調(diào)用的 最后方法,它將返回代表視圖的一個(gè)對象,通常它是一個(gè)字符串。例如:在HTML視圖類中為的html 標(biāo)簽(markup),當(dāng)然它可以是任何東西。最主要的原因是定制導(dǎo)出時(shí),你應(yīng)該返回一些其他的對象。

    9.2. 表視圖

    eXtremeTable的所有標(biāo)簽(markup)在兩個(gè)地方生成:View或Cell。 組合使用他們, 能為你提供一種可插接的表示內(nèi)容的解決方案。為了使用定制的View, 只需要使用TableTag的view屬性來指定實(shí)現(xiàn)View接口的實(shí)現(xiàn)類的 全路徑:

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

    9.3. 導(dǎo)出視圖

    與表視圖不同,export的所有標(biāo)簽都在View中生成。為了使用定制的View, 只需要使用ExportTag的view屬性來指定實(shí)現(xiàn)View接口的實(shí)現(xiàn)類的 全路徑:

    <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使用的默認(rèn)屬性值,我在屬性文件中配置所有用到的屬性。 如果你需要覆蓋任何默認(rèn)的設(shè)置,你可以創(chuàng)建自己的extremecomponents.properties文件 并設(shè)置你想改變的值。

    為了設(shè)置屬性文件,你應(yīng)該如下例所示在/WEB-INF/web.xml文件中聲明一個(gè)context-param,并 指定你的屬性文件的路徑:

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

    你可以認(rèn)為屬性文件為你提供了一個(gè)對所有的eXtremeTables聲明全局設(shè)置的一個(gè)方法。 創(chuàng)建屬性文件的最大好處就是避免在標(biāo)簽中復(fù)制、粘貼相同的屬性。典型的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使用最多的兩個(gè)屬性是:imagePath和rowsDisplayed。如果你不在屬性文件中聲明 這些屬性,你需要在每個(gè)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>

    正如你所見,屬性文件避免了重復(fù)編碼。

    10.3. ColumnTag

    在屬性文件定義的ColumnTag使用最多的兩個(gè)屬性是:parse和format。如果你不在屬性文件中聲明 這些屬性,你需要在每個(gè)eXtremeTable中添加他們。典型的列使用日期cell如下所示:

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

    如果在屬性文件聲明parse和format,則列如下所示:

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

    當(dāng)然你仍然可以定義parse和format屬性來覆蓋全局設(shè)置,但是大多數(shù)工程對于日期使用一致的parse 和format。需要注意屬性文件中parse.date和format.date的聲明語法。

    下例為使用貨幣cell的典型列:

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

    如果在屬性文件聲明format,則列如下所示:

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

    另外,你可以聲明一個(gè)定制的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屬性是我定義其他不同屬性默認(rèn)值時(shí)經(jīng)常使用的方法。你可能對我 使用cell="date"來指定日期cell、使用cell="currency"來指定貨幣cell或使用view="xls."來指定xls導(dǎo)出感到疑惑。 如果我給你展示extremetable.properties文件的一些片斷,這些就將非常清晰了。 extremetable.properties是eXtremeTable聲明默認(rèn)設(shè)置的屬性文件,你可以通過使用 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

    當(dāng)你在列上定義cell="date"時(shí),eXtremeTable尋找到column.cell. 屬性并將你定義的cell屬性值拼接上。 換句話說cell="date"關(guān)聯(lián)到column.cell.date=org.extremecomponents.table.cell.DateCell這條屬性。使用屬性文件 真正強(qiáng)大的地方在于你能夠在extremecomponents.properties文件中聲明一個(gè)定制的cell,并在ColumnTag中通過 名稱來使用它。

    再使用一個(gè)實(shí)例來闡明這一點(diǎn),是否記得ColumnTag章Cell節(jié)中如何調(diào)用一個(gè)名為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

    現(xiàn)在可以通過名稱調(diào)用MyCell:

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

    正如你所見的這能幫助保持代碼清潔,并且這些都在一個(gè)地方定義。如果你的定制cell聲明 需要改變你只需要修改屬性文件。

    Chapter 11. Messages

    11.1. 資源綁定

    為了設(shè)置資源綁定,你應(yīng)該如下例所示在/WEB-INF/web.xml文件中聲明一個(gè)context-param,并 指定你的資源文件的路徑:

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

    本示例中資源文件為extremecomponentsResourceBundle,它可以為任何名或者使用已經(jīng)存在的資源文件。

    如果你不指定locale,則它將根據(jù)你的servlet request來決定使用哪個(gè)資源文件。 在eXtremeTable中可以通過使用TableTag的locale屬性來設(shè)置它。

    <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來與用戶交互,包括:狀態(tài)欄的文本信息,Rows Displayed droplist和不同的tooltips。如果你足夠幸運(yùn),eXtremeTable已經(jīng)提供了相應(yīng)的語言支持 的話,那么你什么也不用擔(dān)心。否則的話,你需要申明下列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

    現(xiàn)在僅支持英語和德語。如果你使用其他語言的話,并能提供相應(yīng)的翻譯的話我將不勝感激。你可以通過 extremecomponents@gmail.com發(fā)送給我。

    譯者注:我已經(jīng)提供了中文和日文的資源文件。

    11.3. TableTag

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

    在eXtremeTable中,imagePath屬性有一個(gè)特定的key:table.imagePath。你可以在你的資源文件中 設(shè)置這個(gè)key為特定語言的目錄結(jié)構(gòu)。例如:德文圖片可能放在de文件夾下,那么你可以在相應(yīng)的資源文件中 進(jìn)行如下設(shè)置:

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

    title有一點(diǎn)不同,如果你指定的title屬性值包含dot (.)并且你定義了一個(gè)資源文件,那么 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屬性有一個(gè)特定的key:table.fomat.type。參考屬性文件的討論 來了解更多的細(xì)節(jié),他們具有同樣的概念。日期和貨幣的format類型定義可能如下所示:

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

    title有一點(diǎn)不同,如果你指定的title屬性值包含dot (.)并且你定義了一個(gè)資源文件,那么 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指南

    默認(rèn)的情況下eXtremeTable取得所有的結(jié)果集然后處理Beans集合,這樣的好處是 你可以隨意進(jìn)行排序、過濾和分頁操作。你只需要組裝Beans集合并讓eXtremeTable知道如何 引用它。這樣的操作對于小到中等數(shù)據(jù)量的結(jié)果集非常有效,當(dāng)結(jié)果集很大時(shí)這將非常糟糕。 這是一個(gè)判斷,但我更喜歡描述如何做出我的技術(shù)決定。如果您認(rèn)為在性能上有問題, 那么最好是使用一個(gè)profiler工具記錄并查看它。有許多開源和商業(yè)的profiler工具可以幫助 你做出最好的判斷。因此,假設(shè)我們發(fā)現(xiàn)了性能上存在問題,需要我們自己來處理分頁。

    手動(dòng)處理分頁意味著你一次只想取得一頁顯示需要的結(jié)果集。同時(shí),你需要自己處理排序、過濾和分頁。 下面的討論是基于我假設(shè)你從數(shù)據(jù)庫中取得集合,當(dāng)然同樣的原理能應(yīng)用到任何地方。

    這是一個(gè)重要的部分。為了得到較小的結(jié)果集,你可以創(chuàng)建一個(gè)普通的查詢語句,但是limit你得到的結(jié)果集。 在Sybase和SQLServer中你可以使用rowcount命令,在MySql中你可以使用limit命令。 我不知道其他數(shù)據(jù)庫怎么使用,但我確信每個(gè)數(shù)據(jù)庫都有相似的功能。 也就是說當(dāng)用戶瀏覽第一頁是得到第一頁需要的 結(jié)果集,當(dāng)用戶瀏覽下一頁時(shí),再得到下一頁需要的結(jié)果集。

    使用Sybase的開發(fā)人員可能會(huì)說:rowcount命令總是從第一條開始,那么當(dāng)我到第二頁時(shí)我也必須 從第一條數(shù)據(jù)開始。 是的,你現(xiàn)在得到的是兩頁的結(jié)果集,而不需要得到所有的結(jié)果集。當(dāng)你到第三頁時(shí),你只需要得到三頁的結(jié)果集。。。。。。 其他數(shù)據(jù)庫比如MySQL,允許你精確地得到你想要的那段數(shù)據(jù),這樣你就可以只得到當(dāng)前頁面顯示需要的結(jié)果集。

    為了知道用戶想如何排序和過濾,他們想瀏覽哪一頁,一頁需要顯示幾條結(jié)果,eXtremeTable有一個(gè)使用LimitFactory 創(chuàng)建的名為Limit的簡便接口:

    12.2. 創(chuàng)建Limit

    首先你需要通過LimitFactory得到一個(gè)Limit實(shí)例:

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

    Limit對象定義了limit結(jié)果集的所有方法。

    TableLimitFactory具有另外一個(gè)構(gòu)造函數(shù),如果沒有指定tableId的話默認(rèn)的tableId將為ec。

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

    12.3. Filter和Sort屬性

    當(dāng)你對Limit實(shí)例化時(shí),實(shí)例化對象包含兩個(gè)對象:FilterSet和Sort。

    private FilterSet filterSet;
    private Sort sort;

    FilterSet包含一個(gè)過濾動(dòng)作(Action)和一個(gè)過濾器對象數(shù)組。 動(dòng)作為TableConstants.FILTER_ACTION或TableConstants.CLEAR_ACTION。 一個(gè)過濾器包含一個(gè)property和這個(gè)過濾器的值。

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

    Sort對象包含property和sortOrder。sortOrder為 TableConstants.SORT_ASC或TableConstants.SORT_DESC:

    private Sort sort;

    12.4. 設(shè)置頁和行屬性

    設(shè)置行屬性:

    limit.setRowAttributes(totalRows, DEFAULT_ROWS_DISPLAYED);

    下面是設(shè)置行屬性可能用到的信息:

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

    每個(gè)變量都有一個(gè)getter方法,我將不深入講解屬性的細(xì)節(jié)。

    12.5. Setup

    在你完成所有的定制工作:排序、過濾.....定制的Controller(Spring)或者Action(Struts)或者其他類似的框架后, 另外你需要?jiǎng)?chuàng)建一個(gè)callback,eXtremeTable已經(jīng)提供了一個(gè)名為LimitCallback的實(shí)現(xiàn)。為了使用你只需要設(shè)置表 屬性: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,同時(shí)傳輸totalRows屬性。 totalRows表示總行數(shù),使用PaginationCallback.TOTAL_ROWS靜態(tài)變量將易于維護(hù)。 如果JSP頁面使用了兩個(gè)(以上)eXtremeTable的話你可以利用tableId分別傳輸totalRows。 例如如果tableId名為pres,你可以如下處理:

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

    譯者注:關(guān)于limit使用的更詳細(xì)信息,請參考《Limit指南》。

    Chapter 13. AutoGenerateColumns

    13.1. 引言

    大多數(shù)情況下你按照你需要的列來設(shè)計(jì)數(shù)據(jù)庫表。但是,有時(shí)候需要運(yùn)行時(shí)動(dòng)態(tài)生成一些列。 為了實(shí)現(xiàn)這點(diǎn),eXtremeTable需要使用ColumnsTag并設(shè)置autoGenerateColumns屬性。

    AutoGenerateColumns為singleton并且不是線程安全的,因此不要定義任何類變量。

    13.2. ColumnsTag

    ColumnsTag只有autoGenerateColumns這一個(gè)屬性。所有你必須做的就是實(shí)現(xiàn)AutoGenerateColumns接口, 并設(shè)置autoGenerateColumns屬性為類的全路徑。

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

    AutoGenerateColumns接口只有一個(gè)方法:

    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()方法簡單返回一個(gè)包含生成列(columns)需要的所有信息的集合。 作為參考,下面是我在eXtremeComponents網(wǎng)站實(shí)例中使用的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;
    }

    另外,我想聲明的是只創(chuàng)建列一次。eXtremeTable為了高效,不會(huì)每行創(chuàng)建一列, 而是通過循環(huán)持續(xù)插入新列值到已經(jīng)存在的列。記住TableModel能夠訪問Context,因此 你可以在Controller(Spring)或Action(Struts)中定義樣式(look like)并通過request傳輸集合。 所以你得AutoGenerateColumns實(shí)現(xiàn)只需要構(gòu)建列(Columns)并添加到model.columns里。

    Chapter 14. Utilities

    14.1. 引言

    eXtremeTable包含許多Utility類。在這里我只簡單地討論一些,你可以通過javadocs 得到更多的信息。

    14.2. HtmlBuilder

    封裝了所有html語法的類。這個(gè)簡單類的使你能夠?qū)懗龈蓛舻膆tml代碼,而不用擔(dān)心null或空字符串。 一個(gè)span標(biāo)簽的示例代碼如下:

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

    Chapter 15. 1.0.1-M4升級(jí)說明

    15.1. 變更概述

    下面的特性已經(jīng)被更改:

    • HtmlView基于原來代碼的實(shí)現(xiàn)已經(jīng)deprecated

    • Cell接口更簡單

    • 增加RowTag

    • AutoGenerateColumns變?yōu)閟ingleton,更易添加列屬性

    • Extended Attributes方法名變更

    • TableTag的collection屬性被刪除

    • BaseModel更名為TableModel

    • Properties和ResourceBundle現(xiàn)在為Preferences和Messages

    • pageContext被Context接口代替

    • Limit和LimitFactory的語法變更,更易于使用

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

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

    • search圖片的名稱變?yōu)閒ilter

    • FormTag/InputTag為deprecated

    • RetrieveRowsCallbacks、FilterRowsCallback、SortRowsCallback都變?yōu)閟ingletons

    15.1.1. HtmlView

    我把和舊的view相關(guān)的代碼:原始的view、cell和相關(guān)代碼放到deprecated文件夾。 原因是新的view代碼非常成功,所以沒有必要使用舊的代碼。使用新代碼構(gòu)建定制view請參考 view包中的HtmlView或CompactView。

    15.1.2. Cell

    Cell接口已經(jīng)改變,原因是想結(jié)束混亂以提高靈活性。以前對于如何處理區(qū)分html和export顯示值 不是十分明顯。現(xiàn)在Column值設(shè)置html,Column的propertyValue設(shè)置export。另外因?yàn)镃olumn值和 propertyValue值被重寫。現(xiàn)在他們在view中是不可見的。

    cell現(xiàn)在是singleton并且不再線程安全,因此不要定義任何類變量。改變的原因是為 了Cell接口能更簡單地被使用。init()和destroy()方法作為singleton更靈活但是處于一種混亂的狀態(tài)。

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

    現(xiàn)在得到導(dǎo)出和html顯示存在明顯的區(qū)別。更重要的,需要返回字符串。列值和屬性值不再 需要設(shè)置。另一個(gè)細(xì)微的區(qū)別是:BaseModel已經(jīng)被TableModel取代。這種改變是的不再需要一個(gè) 基礎(chǔ)包(base package),這意味著不再需要BaseModel。

    cell變?yōu)閟ingleton不會(huì)導(dǎo)致使用復(fù)雜,如果你定義了任何類變量只需要把他們放到正確的 方法那么他們就能被任何其他方法使用。

    BaseCell被刪除因?yàn)椴辉傩枰砑尤魏沃怠L娲氖茿bstractCell,虛擬方法 getCellValue被用來返回cell的值。這種方法非常容易使用并不需要關(guān)心markup。查看 AbstractCell也是有意義的,你會(huì)發(fā)現(xiàn)這代碼實(shí)現(xiàn)的多么簡單。然而,很多時(shí)候需要做的僅僅是 實(shí)現(xiàn)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> 現(xiàn)在被需要,它被用來替代columns。 現(xiàn)在看來它一直被需要。它不知道表中到底有多少列,最近重構(gòu)的時(shí)候我通過 Table -> Row -> Column使結(jié)構(gòu)固定來合并得到更好的靈活性。將來我可能提供更多的 特性,因?yàn)槲抑纄XtremeTable有著清晰的架構(gòu)。

    典型的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得到了很大的提高,現(xiàn)在你只需要設(shè)置你需要的屬性。 當(dāng)你添加列到ColumnHandler使,defaults將別自動(dòng)調(diào)用。

    AutoGenerateColumns為singleton并且不是線程安全的,因此不要定義任何類變量。

    現(xiàn)在它的實(shí)現(xiàn)可能如下:

    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方法重命名使得如何使用這個(gè)特性更清晰。 因此RowTag的addExtendedAttributes現(xiàn)在變?yōu)閍ddRowAttributes,ColumnTag變 為addColumnAttributes,TableTag變?yōu)閍ddTableAttributes,ExportTag變 為addExportAttributes。另外你參考正確的model bean(它的實(shí)現(xiàn)更清晰), 將知道如何添加屬性到你的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中g(shù)et它:

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

    現(xiàn)在你需要在ExportTag中覆蓋它,你只需要調(diào)用setter方法。如果是新的屬性,那么使用 可以和前一版一樣使用addAttribute()方法。為了得到值,首先從ExportHandler得到Export, 然后調(diào)用需要的getter方法。這和使用其它tags一樣。

    在RowTag和ColumnTag中增加了兩個(gè)新的callback方法:modifyRowAttributes和 modifyColumnAttributes,因此你可以在rows/columns被處理時(shí)改變屬性值。

    15.1.6. TableTag的collection屬性

    TableTag的collection屬性被刪除,現(xiàn)在變?yōu)槿齻€(gè)新屬性:tableId、items和var。 因?yàn)槲野凑諛?biāo)準(zhǔn)的JSTL命名,你應(yīng)該能夠根據(jù)這些名稱知道他們的作用。tableId屬性 被用來作為表的唯一標(biāo)識(shí),items屬性用來表示從各種servlet的scopes里取得的集合, var屬性表示你將使用EL編寫腳本的名稱。

    依賴你的需要來決定如何使用新的屬性,tableId用來唯一標(biāo)識(shí)表。如果你的頁面上只使用了 一個(gè)eXtremeTable并且不使用Limit特性,那么你根本不需要定義它。默認(rèn)的表示名為'ec';如果使用 Limit特性你也可以使用'ec'這個(gè)名稱。然而,如果的一個(gè)JSP頁面上同時(shí)使用兩個(gè)eXtremeTables你就 需要使用tableId來唯一標(biāo)識(shí)他們。var屬性被用來你將使用EL編寫腳本的名稱。items屬性用來表示從 各種servlet的scopes里取得的集合,而且現(xiàn)在非常健壯。你現(xiàn)在能nest集合到另外的對象,或者nest你想的 深度。

    取得集合的語法如下:

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

    本示例將從命令對象(command object)取得myCol集合。

    <ec:table items="myCol" />

    本示例中將根據(jù)名稱自動(dòng)取得集合,就像以前版本的collection屬性一樣。

    15.1.7. BaseModel

    BaseModel被重命名為TableModel,這是因?yàn)橐呀?jīng)不需要一個(gè)基礎(chǔ)包(base package)了,這也 意味著不再需要BaseModel了。

    15.1.8. Properties和ResourceBundle

    web.xml文件中使用extremecomponentsPreferencesLocation屬性取代extremecomponentsPropertiesLocation屬性, properties現(xiàn)在被Preferences接口控制。在以后的版本,我將提供可選的xml文件配置。

    eXtremeTable不再默認(rèn)在頂層類路徑(top level classpath)尋找 extremecomponents.properties文件。你應(yīng)該在web.xml中使用設(shè)置context-param屬性的 值為extremecomponentsPreferencesLocation,這將更為通用。

    web.xml文件中使用extremecomponentsMessagesLocation屬性取代extremecomponentsResourceBundleLocation屬性, internationalization現(xiàn)在被Messages接口控制。

    Properties和ResourceBundle屬性根據(jù)table、row、column、export和filterare區(qū)分開。 在以前版本中每個(gè)屬性都以'table'開頭,現(xiàn)在每個(gè)屬性關(guān)聯(lián)到被使用的標(biāo)簽。另外poperty不再需要使用奇怪的下劃線語法, 而是使用dot來強(qiáng)調(diào)。

    下面為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接口, 默認(rèn)的被pageContext支持。直接訪問pageContext是一個(gè)不好的實(shí)現(xiàn),Context提供你需要從不同servlet scopes中 取得需要屬性值的所有方法。然而,如果你需要直接訪問背后的對象,可以使用getContextObject()方法。

    15.1.10. Limit和LimitFactory

    Limit和LimitFactory現(xiàn)在都是接口,以前版本的實(shí)現(xiàn)不如我想象的簡單。然而, Limit對象的方法命名和以前版本的一樣,因此你以前的代碼也能很好的工作。

    我兩個(gè)Limit實(shí)現(xiàn)重構(gòu)為一個(gè),但是仍有兩個(gè)LimitFactory實(shí)現(xiàn), 從coding的觀點(diǎn)用戶只要使用一個(gè) 實(shí)現(xiàn),但是它必須兼容以前的版本。現(xiàn)在只有一個(gè)Limit實(shí)現(xiàn)我重命名為TableLimit。同時(shí),因?yàn)長imit特性 依賴Context而不是request,我重命名工廠類(TableLimitFactory)來reflect它。

    Limit在導(dǎo)出時(shí)正確地顯示行信息,Limit具有一個(gè)isExported()方法。

    使用Limit和LimitFactory的示例如下:

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

    設(shè)置row屬性,僅設(shè)置totalRows和默認(rèn)的行顯示:

    limit.setRowAttributes(totalRows, DEFAULT_ROWS_DISPLAYED);

    RequestLimitFactory具有另一個(gè)如果沒有指定tableId將設(shè)置為ec的構(gòu)造函數(shù):

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

    15.1.11. TableTag的saveFilterSort屬性

    saveFilterSort屬性被state屬性取代,state屬性參照State接口并能插接不通的關(guān)于 如何保存表狀態(tài)的實(shí)現(xiàn)。

    State接口如下:

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

    表新增了兩個(gè)屬性:state和stateAttr。state屬性使用預(yù)設(shè)的四種 狀態(tài)(default、notifyToDefault、persist和notifyToPersist)之一, 你也可以插接自己的實(shí)現(xiàn)。default狀態(tài)不維持任何狀態(tài);persist狀態(tài)沒有任何參數(shù)傳入,將一直維持表的狀態(tài); notifyToDefault狀態(tài)將一直維持表的狀態(tài)直到你傳入?yún)?shù)告訴它回到default狀態(tài);notifyToPersist狀態(tài) 將一直維持當(dāng)前狀態(tài)直到你傳入?yún)?shù)告訴它維持persisted狀態(tài)。stateAttr為指定參數(shù)提供了一條途徑,你 也可以使用屬性文件在全局范圍內(nèi)指定它。為了向后兼容,默認(rèn)參數(shù)一直為useSessionFilterSort。

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

    15.1.12. ColumnTag的showTotal屬性

    列新增了兩個(gè)屬性:calc和calcTitle:

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

    calc屬性實(shí)現(xiàn)具有唯一方法的Calc接口:

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

    它傳入model和column,并返回一個(gè)Number型的值。默認(rèn)的實(shí)現(xiàn)為總計(jì)和平均值。

    為了使用定制的Calc,只需要使用ColumnTag的calc屬性來指定實(shí)現(xiàn)Calc接口的實(shí)現(xiàn)類的 全路徑。

    Calc為singleton并且不是線程安全的,因此不要定義任何類變量。

    showTotal因?yàn)椴辉龠m用在新版中被刪除,我也刪除了表中的totalTitle。

    15.1.13. Image名

    search圖片名從search變?yōu)閒ilter。

    15.1.14. FormTag / InputTag Deprecated

    FormTag和InputTag現(xiàn)在為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

    Table 16.9. 

    Name Description
    name The name of the parameter.
    value The value of the parameter.

    posted on 2008-10-31 13:32 蘆葦 閱讀(3530) 評(píng)論(0)  編輯  收藏 所屬分類: HTML & Script
    主站蜘蛛池模板: 亚洲人成无码网WWW| 亚洲精品色午夜无码专区日韩| a级亚洲片精品久久久久久久| 久久精品国产亚洲av高清漫画 | 亚洲精品无码专区久久| aa级毛片毛片免费观看久| 91情侣在线精品国产免费| 亚洲成aⅴ人片久青草影院| 亚洲高清资源在线观看| 日本一区二区在线免费观看 | 国产性生交xxxxx免费| 亚洲人成网www| 黄色网址免费在线| 四虎最新永久免费视频| 久久久久亚洲AV成人网人人软件| 亚洲mv国产精品mv日本mv| 中文字幕免费视频精品一| 天天看免费高清影视| 久久精品亚洲一区二区三区浴池| 一级毛片视频免费观看| 成人a视频片在线观看免费| 无码乱人伦一区二区亚洲| 九九久久精品国产免费看小说| 在线观看视频免费完整版| 久久久久久亚洲av成人无码国产 | 精品亚洲国产成人av| 亚洲免费在线视频播放| 在线精品亚洲一区二区小说| 456亚洲人成在线播放网站| 最近免费中文字幕MV在线视频3 | 最近中文字幕mv手机免费高清| 亚洲欧洲日产国产综合网| 国产高清对白在线观看免费91| 成年性羞羞视频免费观看无限| 777亚洲精品乱码久久久久久| 国产精品无码免费专区午夜| 免费成人黄色大片| 亚洲最大av资源站无码av网址| 57pao一国产成视频永久免费| 亚洲中文久久精品无码| 全黄A免费一级毛片|