昨天公司需求需要实现一个动态列功能,于是研究了一下DisplayTag是否能支持动态列。答案是实现起来也比较简单的。只需要将column用logic:iterate来循环使用就行了:
<%
ArrayList arrList = new ArrayList();
HashMap rowMap = new HashMap();
rowMap.put( " dunPersonel " , " xxx " );
rowMap.put( " taskPackageNumber " , " xxx " );
ArrayList colList = new ArrayList();
colList.add( " 1 " );
colList.add( " 2 " );
colList.add( " 3 " );
rowMap.put( " titlenum " , colList);
rowMap.put( " data1 " , " 23432 " );
rowMap.put( " data2 " , " 35221 " );
rowMap.put( " data3 " , " 52.23 " );
arrList.add(rowMap);
request.setAttribute( " result " , arrList);
%>
< display:table uid = " arow " name = " result " export = " false " pagesize = " 10 "
class = " paging_table "
requestURI = " /creditcarddun/reclaimRatioStatistics.do " >
< display:setProperty name = " basic.empty.showtable " value = " true " />
< display:caption >
< bean:message key = " caption.cardAccountQuery.cardAccountStatusList " />
</ display:caption >
< display:column titleKey = " label.reclaimRatioStatistics.dunPersonel " property = " dunPersonel " style = " width:20%; " sortable = " true " />
< display:column titleKey = " label.reclaimRatioStatistics.taskPackageNumber " property = " taskPackageNumber " style = " width:20%; " sortable = " true " />
< logic:iterate id = " num " name = " arow " property = " titlenum " >
< display:column titleKey = " label.reclaimRatioStatistics.reclaimRatio " property = " data${num} " style = " width:10% " >
</ display:column >
</ logic:iterate >
<%--< display:column titleKey = " label.reclaimRatioStatistics.reclaimRatio " property = " reclaimRatio " style = " width:10% " sortable = " true " /> --%>
</ display:table >
ArrayList arrList = new ArrayList();
HashMap rowMap = new HashMap();
rowMap.put( " dunPersonel " , " xxx " );
rowMap.put( " taskPackageNumber " , " xxx " );
ArrayList colList = new ArrayList();
colList.add( " 1 " );
colList.add( " 2 " );
colList.add( " 3 " );
rowMap.put( " titlenum " , colList);
rowMap.put( " data1 " , " 23432 " );
rowMap.put( " data2 " , " 35221 " );
rowMap.put( " data3 " , " 52.23 " );
arrList.add(rowMap);
request.setAttribute( " result " , arrList);
%>
< display:table uid = " arow " name = " result " export = " false " pagesize = " 10 "
class = " paging_table "
requestURI = " /creditcarddun/reclaimRatioStatistics.do " >
< display:setProperty name = " basic.empty.showtable " value = " true " />
< display:caption >
< bean:message key = " caption.cardAccountQuery.cardAccountStatusList " />
</ display:caption >
< display:column titleKey = " label.reclaimRatioStatistics.dunPersonel " property = " dunPersonel " style = " width:20%; " sortable = " true " />
< display:column titleKey = " label.reclaimRatioStatistics.taskPackageNumber " property = " taskPackageNumber " style = " width:20%; " sortable = " true " />
< logic:iterate id = " num " name = " arow " property = " titlenum " >
< display:column titleKey = " label.reclaimRatioStatistics.reclaimRatio " property = " data${num} " style = " width:10% " >
</ display:column >
</ logic:iterate >
<%--< display:column titleKey = " label.reclaimRatioStatistics.reclaimRatio " property = " reclaimRatio " style = " width:10% " sortable = " true " /> --%>
</ display:table >