幸せのちから

          平凡的世界
          看似平常實崎嶇
          成如容易卻艱辛

          Chapter 10. Preferences

          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聲明 需要改變你只需要修改屬性文件。

          posted on 2006-02-28 09:53 Lucky 閱讀(665) 評論(0)  編輯  收藏 所屬分類: extremeComponents

          <2006年2月>
          2930311234
          567891011
          12131415161718
          19202122232425
          2627281234
          567891011

          導航

          隨筆分類(125)

          文章分類(5)

          日本語

          搜索

          積分與排名

          最新隨筆

          最新評論

          主站蜘蛛池模板: 大洼县| 拜城县| 洛宁县| 汨罗市| 汉寿县| 开远市| 深水埗区| 体育| 永安市| 隆尧县| 平凉市| 淅川县| 突泉县| 霍城县| 富蕴县| 新化县| 乌兰浩特市| 长白| 永顺县| 高平市| 正阳县| 杭锦后旗| 揭东县| 尖扎县| 泗阳县| 湄潭县| 伊宁县| 墨江| 漠河县| 永川市| 蓬溪县| 绵阳市| 黔江区| 宜昌市| 左贡县| 化州市| 辽中县| 富平县| 修文县| 宜昌市| 商都县|