版 本 號: 1.0
功 ? ?? 能:表格處理
參考文檔: displaytag.pdf
實 例 包: displaytag.war
簡要說明
1.? 已知條件:
1 )存在一個 JavaBean : Computer(id , mainboard , cpu , keyboard , mouse , buyTime)
2 )存在一個 Collection( 包含五條 Computer 記錄 ) : computer
?????? 3 ) request 存放該 Collection : request.setAttribute(“test” , computer) ;
??????
2.? 將 Collection 里的記錄生成一張表
代碼: <display : table? name=”test”/>
說明:該表中包含以 test 命名的 Collection 的五條記錄,顯示的列為該 Computer
類的所有屬性。
3.? 有選擇的顯示列
代碼:
<display : table? name=”test” >
?????????????? <display : column? property=”id” title=”ID” />
?????????????? <display : column? property=”mainboard” />
?????????????? <display : column? property=”cpu” />
?????????????? <display : column? property=”buyTime” />
????? </display : table>
說明: property :代表要顯示的列,若不指定 title 則列名默認為 property 指定的屬性名。
???? 也可以增加其它自定義列,例如:
<display:column title="
操作
">
刪
除
</display:column>
4.? 指定以某列值進行排序
代碼:
<display : table? name=”test” defaultsort="1" defaultorder="descending" >
?????????????? <display : column? property=”id” title=”ID” ?sortable="true"/>
?????????????? <display : column? property=”mainboard” />
?????????????? <display : column? property=”cpu” />
?????????????? <display : column? property=”buyTime” ?sortable="true"/>
????? </display : table>
說明: defaultsort : 在還未點擊可排序列時的默認狀態
????? defaultorder :指明默認是升序還是降序進行排序( ascending /descending )
????? sortable :在要進行排序的列上指明該屬性為 true ,則每點擊一次該列都會以升序或降序進行表格重排。
5.? 創建動態連接
代碼:
<display : table? name=”test” >
? ???<display : column? property=”id” title=”ID” href=”details.jsp” paramId=”id” />
? ???<display : column? property=”mainboard” ?href=”details.jsp” ?????????????????????????????????????????????? ?paramId=”action”? paramName=”testparam” />
? ???<display : column? property=”cpu” ?href=”details.jsp” paramId=”id”
paramScope =”request” paramProperty=”id”/>
? <display : column? property=”buyTime”? />
</display : table>
說明:
href :
the base URL used to construct the dynamic link
paramId:
the name of the parameter that gets added to the URL specified above
paramName:
name of the bean that contains the data we want to tack on the the URL
(typically null, indicating the current object in the List)
paramProperty:
property to call on the object specified above to return the value that
??????????????????
??
gets tacked onto the URL.
paramScope:
specific scope where the databean lives, typically null
6.? 翻頁功能 ( 每頁顯示 2 條記錄 )
<display
:
table ?name=” test”
pagesize
="2"
/>
7.? 表頭、表尾說明
表頭: <display : caption>this is a table caption</display : caption>
表尾:
<display:footer>
??? ?<tr>
????? ??<td colspan="3">sample footer</td>
????? ??<td>any sum or custom code can go here</td>
??? ?</tr>
</display:footer>
8.? 列表所處范圍
pageScope
requestScope (
默認
)
,前面所介紹的
test
都是從
request
中取出。
sessionScope
applicationScope
例:從
sessionScope
中取出列表
test2