如何在Struts 2中的迭代器中显示预先检查的复选框 [英] How to display pre-checked checkboxes inside iterator in Struts 2

查看:65
本文介绍了如何在Struts 2中的迭代器中显示预先检查的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要遍历 List< String> ,每个元素都有 s:checkbox

I need to iterate through List<String>, each element has s:checkbox.

我在Action层中定义了一个列表,以保留选定的元素。

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 包含字符串对象列表。

Value1 contains list of String objects.

functionCheckBoxList -我定义为保留选中元素的列表

functionCheckBoxList - The list I have defined to keep checked element

在加载时,我向 Value1 所属的 functionCheckBoxList 添加了一些元素。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆