struts2对于checkboxlist的换行

在struts2中,checkboxlist会自动继承checkboxlist.ftl模板(在struts-core.rar中),如果我们要进行格式化换行输出则需要更改模板中的类容。
对此应注意以下几点:
1.模板内容如下:
<#assign itemCount = 0/>

<#if parameters.list?exists>

<@s.iterator value="parameters.list">
<#assign itemCount = itemCount + 1/>
<#if parameters.listKey?exists>
<#assign itemKey = stack.findValue(parameters.listKey)/>
<#else>
<#assign itemKey = stack.findValue('top')/>
</#if>
<#if parameters.listValue?exists>
<#assign itemValue = stack.findString(parameters.listValue)/>
<#else>
<#assign itemValue = stack.findString('top')/>
</#if>
<#assign itemKeyStr=itemKey.toString() />
<#if itemCount-1%7 == 0>
<tr>
</#if>

<td width="180">
<input type="checkbox" name="${parameters.name?html}" value="${itemKeyStr?html}" id="${parameters.name?html}-${itemCount}"<#rt/>
<#if tag.contains(parameters.nameValue, itemKey)>checked="checked"<#rt/>
</#if>
<#if parameters.disabled?default(false)>disabled="disabled"<#rt/>
</#if>
<#if parameters.title?exists>title="${parameters.title?html}"<#rt/>
</#if>
<#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
<#include "/${parameters.templateDir}/simple/common-attributes.ftl" />
/>
<label for="${parameters.name?html}-${itemCount}" class="checkboxLabel">${itemValue?html}</label>
</td>

<#if itemCount%7 == 0>
</tr>
</#if>

</@s.iterator>
</tr>

<#else>
 
</#if>

2.每行要显示多少列,则将模板中的7改成对应的即可;
3.标签的写法:
<s:checkboxlist name="staffInfo.jobStaffDepartList.job_id" list="jobInfos" listKey="jobId" listValue="jobName" theme="xhtml" template="customcheckboxlist.ftl" > </s:checkboxlist>
在这里theme="xhtml"其实表示的意思是customcheckboxlist.ftl所在原项目(不是发布了的项目)下的template文件夹下的一个文件夹,为了不与原来的checkboxlist.ftl相冲突,所以用了customcheckboxlist.ftl,则不会影响其它checkboxlist的使用。
4.记得修改后,重新发布项目,重新启动服务器。

注:此想法以及附件代码最开始来自于一位网上朋友,只是当时忘记了她的地址,还请原谅。在使用的过程中遇到了一些新的问题,我在上面进行了总结。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值