幸せのちから

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

          Chapter 10. Preferences

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

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

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

          導(dǎo)航

          隨筆分類(125)

          文章分類(5)

          日本語

          搜索

          積分與排名

          最新隨筆

          最新評(píng)論

          主站蜘蛛池模板: 九台市| 洛南县| 赤壁市| 莫力| 桐梓县| 古田县| 鹤岗市| 沐川县| 乐都县| 铁力市| 黄陵县| 会宁县| 公主岭市| 溧水县| 修文县| 兴海县| 云南省| 乌恰县| 磴口县| 汾阳市| 屏边| 宕昌县| 南川市| 庆元县| 垣曲县| 新巴尔虎左旗| 乐陵市| 古交市| 和平县| 安西县| 卫辉市| 麻阳| 凤山县| 彩票| 辽源市| 莒南县| 三亚市| 天全县| 安岳县| 巫山县| 团风县|