在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.记得修改后,重新发布项目,重新启动服务器。
注:此想法以及附件代码最开始来自于一位网上朋友,只是当时忘记了她的地址,还请原谅。在使用的过程中遇到了一些新的问题,我在上面进行了总结。
对此应注意以下几点:
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.记得修改后,重新发布项目,重新启动服务器。
注:此想法以及附件代码最开始来自于一位网上朋友,只是当时忘记了她的地址,还请原谅。在使用的过程中遇到了一些新的问题,我在上面进行了总结。