在相應的jsp文件中加入如下代碼測試生成動態的鏈接
<%
List hrefList = new ArrayList();
for (int i = 0; i < 5; i++) {
hrefList.add(new LabelValueBean("Label" + i, "Value" + i));
}
request.setAttribute("hrefList", hrefList);
%>
<display:table name="hrefList" scope="request" decorator="test.MySimpleWrapper">
<display:column property="label"/>
<display:column property="value"/>
<display:column property="href" title="Actions"/>
</display:table>
其中test.MySimpleWrapper是自定義的decorator,繼承自org.displaytag.sample.Wrapper(1.0)或者org.displaytag.sample.decorators.Wrapper(1.1)。
其中添加相應的set方法,例如這裏href是LabelValueBean中沒有的字段,將由MySimpleWrapper
來處理,所以應該定義getHref()方法,如下:
//------------------------------------------
public String getHref()
{
int index= getListIndex();
return "<a href=/"XXXX=" + index + "/">" + "Link" + index + "</a>";
}
//----------------------------------------------
該方法返回一個代表url鏈接的字符串,從而可以生成動態的鏈接。