Posted on 2005-11-21 17:11
qiqijava 閱讀(771)
評論(1) 編輯 收藏 所屬分類:
Tag
當時想要這樣一個標簽,能實現分頁、排序、過濾、搜索功能,且頁面比較美觀。先后學習了三個比較有名的標簽:displayTag、eXtremeComponents、valueList。個人感覺:
display上手容易,功能簡單,界面漂亮,不過功能比較有限。感覺最不爽的就是在一頁上排好序后,再點擊下一頁后,排序就亂了。而且當數據量大時,它的排序會有問題
eXtremeComponents上手容易,操作煩索,界面一般,不過起碼在排序上就沒有displayTag的問題。數據量大時,它的排序也會有問題
valueList我認為最強大的標簽,需要與spring結合使用,上手不易,界面漂亮,功能超強。目前沒有發現任何不爽的地方。
先貼出display的心得,后續會貼出其它兩個的心得
displayTag學習摘要
1.tableTag中name屬性:值默認作用域:request
<display:table name="accList">
如果作用域為session,則<display:table name="sessionScope.accList">
tableTag中指定ID屬性會把該對象加入到pageContext對象中去。如ID="test"
<%int cate=((Role)pageContext.getAttribute("test")).getCategory();%>
生成表格的序列號 例如:<display:table id="row" name="mylist">
<display:column title="序列號"><%=pageContext.getAttribute("row_rowNum")%></display:column>
如行號:row_rowNum <c:out value="${row_rowNum}"/>
firstName:row.firstName <c:out value="${row.firstName}"/>
lastName: row.lastName 全部由ID來取得
2.限制頁面顯示的結果集數
1)全部<display:table name="accList" class="its" id="test">
2)頭5個<display:table name="accList" class="its" id="test" length="5">
3)從第二個開始,顯示下5個<display:table name="accList" class="its" id="test" offset="2" length="5">
3.包裝器decorators,有行包裝器(必須繼承TableDecorator)和列包裝器(必須實現ColumnDecorator)
在tableTag中顯示list時,decorators中的方法會在list前調用,如果decorators實現類中有相關的getXXX()方法時,調用此方法,如果沒有,則直接調用list
在columnTag中顯示value時,decorators中的方法會先調用,(應該重用)
4.傳遞參數,有兩種方式,
一。struts方式:有以下幾個屬性
1)href 基本的超連接
2)paramId 添加到url上的參數名
<display:column property="status" href="details.jsp" paramId="id" paramProperty="id" />
3)paramName 傳遞容器內的其它bean當作參數 如:request.setAttribute("testparam", "sendamail");
<display:column property="email" href="details.jsp" paramId="action" paramName="testparam" paramScope="request" />
4)paramScope 指定bean的作用域
二。decorators方式
類Wrapper方法:public String getLink1()
{
ListObject lObject= (ListObject)getCurrentRowObject();
int lIndex= getListIndex();
return "<a href="details.jsp?index=" + lIndex + "">" + lObject.getId() + "</a>";
}標簽:
<display:table name="sessionScope.details" decorator="org.displaytag.sample.Wrapper" >
<display:column property="link1" title="ID" />
<display:column property="email" />
</display:table>
5.分頁
指定屬性:pagesize="10" 每頁顯示10條記錄
6.排序
1)在list中封裝的對象的屬性要實現Comparable接口,(一般均實現了)
2) 在columnTag中指定sortable="true"
可指定默認排序的列 defaultsort="1" 數值為第幾列默認排序 defaultorder="descending" 指定默認為降序
7.導出 支持下列格式:'html', 'xml', 'csv', and 'excel'.
屬性:export="true",注意導出無效,當使用jsp:include or the RequestDispatcher
<display:column media="csv excel" title="URL" property="url"/>
指定該url屬性值只能在csv、excel中導出
需要指定export filter.
8.更改默認設置
1)通過<display:setProperty name=... value=...> 標簽,可以覆蓋一些默認設置
2)創建displaytag.properties文件,所有時區共用,建中文編碼則創建displaytag_zh_cn.properties,放到類路徑下,jar包內共有兩個默認的屬性文件TableTag.properties,message.properties
9其它
1)當多個表在一頁顯示時,每個表都想要有分頁、排序、導出等功能時,只需為每個table指定一個不同的ID即可。
2)增加表頭<display:caption>角色管理</display:caption>
3)增加表尾 <display:footer><tr><td colspan="6" align="center" >國瑞數碼版權所有</td></tr></display:footer>
4)http和email自動鏈接功能,指定autolink="true"
5)指定一列顯示的最大長度,避免太長把表格變形 maxLength="10" style="whitespace: nowrap;"
6)當列的值為null,使用nulls="false"屬性把null轉為空白