如何在 Struts 2 的迭代器中显示预先选中的复选框 [英] How to display pre-checked checkboxes inside iterator in Struts 2
问题描述
我需要遍历List<String>
,每个元素都有s:checkbox
.
I need to iterate through List<String>
, each element has s:checkbox
.
我在动作层定义了一个列表来保留选定的元素.
I have defined one list in Action layer to keep selected elements.
使用我的代码,我可以提交表单并在操作层中捕获选定的值.但是,必须预先选中某些复选框.加载页面时无法显示预检查状态.
Using my code I can submit my form and capture selected values in action layer. But, some of the checkboxes must be pre-checked. I cannot display pre- checked status when loading the page.
Value1
包含 String 对象的列表.
Value1
contains list of String objects.
functionCheckBoxList
- 我定义的用于保留选中元素的列表
functionCheckBoxList
- The list I have defined to keep checked element
在加载时,我向 functionCheckBoxList
添加了一些属于 Value1
的元素.
While loading, I added some element to functionCheckBoxList
that belongs to Value1
.
但仍然没有在页面中显示预先检查的状态.
But still does not show pre-checked status in the page.
<s:iterator value="value1" var ="functionName">
<s:checkbox fieldValue="%{#functionName}" name="functionCheckBoxList"
value="%{#functionName}" theme="simple" >
</s:checkbox>
</s:iterator>
注意:我知道如何使用 s:checkboxlist
来做到这一点,但不能在这里,因为我需要在迭代中使用特殊格式.
Note: I know how to do it using s:checkboxlist
but can't here as I need special format in the iteration.
推荐答案
我可以找到解决我的问题的方法,我想与大家分享.
i could find a solution for my problem, i would like to share it with everyone.
<s:iterator value="value1" var ="functionName">
<s:checkbox fieldValue="%{#functionName}" name="functionCheckBoxList"
value="%{#functionName in functionCheckBoxList}" theme="simple" >
</s:checkbox>
</s:iterator>
这篇关于如何在 Struts 2 的迭代器中显示预先选中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!