使用struts2 checkboxlist标签设置cssClass属性后,发现生成的html代码中 input 标签并没有class属性。
打开checkboxlist.ftl看,内容如下:
<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??>
title="${parameters.title?html}"<#rt/>
</#if>
<#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
<#include "/${parameters.templateDir}/simple/common-attributes.ftl" />
/>
根本没有cssClass参数进行设置。
添加下面的内容,在替换struts2包中的 checkboxlist.ftl 文件就可以了:
<#if parameters.cssClass??>
class="${parameters.cssClass?html}"<#rt/>
</#if>
完整的ftl文件如下:
<#assign itemCount = 0/>
<#if parameters.list??>
<@s.iterator value="parameters.list">
<#assign itemCountitemCount = itemCount + 1/>
<#if parameters.listKey??>
<#assign itemKey = stack.findValue(parameters.listKey)/>
<#else>
<#assign itemKey = stack.findValue('top')/>
</#if>
<#if parameters.listValue??>
<#assign itemValue = stack.findString(parameters.listValue)?default("")/>
<#else>
<#assign itemValue = stack.findString('top')/>
</#if>
<#assign itemKeyitemKeyStr=itemKey.toString() />
<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??>
title="${parameters.title?html}"<#rt/>
</#if>
<#if parameters.cssClass??>
class="${parameters.cssClass?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>
</@s.iterator>
<#else>
</#if>
<input type="hidden" id="__multiselect_${parameters.id?html}" name="__multiselect_${parameters.name?html}" value=""<#rt/>
<#if parameters.disabled?default(false)>
disabled="disabled"<#rt/>
</#if>
/>
分享到:
相关推荐
struts的htmlcheckbox标签的默认选中问题
freemarker初探 附 freemarker中文手册 与 struts2 checkboxlist的研究 入门适用!
(原创)struts标签之checkboxlist选中值并换行处理
巧用struts标签之checkboxlist选中默认值换行处理
NULL 博文链接:https://simle-google.iteye.com/blog/586373
NULL 博文链接:https://xueyue.iteye.com/blog/1158510
工程文件 博文链接:https://selvemen.iteye.com/blog/453223
找了一些关于checkboxList控件的常用用法 添加项,选择项,删除项的等17种常用的方法。 希望对大家有用
ASP.NET 中Checkboxlist添加到数据库代码案例
遍历CheckBoxList,获得选中项的值动态绑定CheckBoxList, 遍历CheckBoxList,获得选中项的值动态绑定CheckBoxList。
在Struts中几种情况可以使标签初始就是选中的,Formbean里面该Property的值设为 1.on 、2.yes 、3.true 这三种情况都是可以实现默认选中的。 注:如果不选中,最好把Property的设置为””,因为在Action中得到...
CheckBoxList操作方法集合,包括:获取选中项、全选、取消、反选
Struts 2 标签库(文档手册) Tags-API-CLSW-JSP <%@ taglib prefix="s" uri="/struts-tags" %> 就能使用struts2.0的标签库 下面就介绍每个标签的具体应用实例说明:按字母排列 A: 1. 2. <s:a href=""></s:a>-...
checkboxlist标签:根据一个集合属性创建一系列的复选框。 combobox标签:生成一个单选文本框和一个下拉列表框的组合。 doubleselect标签:生成一个相互关联的列表框,该标签由两个下拉选择框组成。 ...
实现struts2标签chekboxlist竖排; 可以实现checkboslist横向放置个数(自行修改)
可以设置checkboxlist为单选,
CheckBoxList的操作
CheckBoxList的用法,绑定“多选项”,并在保存时获取被选中项的代码
( CheckBoxList详细用法.doc )
<%@ taglib uri="/struts-tags" prefix="s" %> 结合例子,重点掌握以下标签的用法 (1) (2) (3) <s:if> 、、 (4) (5) (6) 、 (7) 、、<s:checkbox>、 (8) 、、<s:checkboxlist>