How to display pre-checked checkboxes inside iterator in Struts 2

不问归期 提交于 2019-12-01 07:09:21

问题


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 contains list of String objects.

functionCheckBoxList - The list I have defined to keep checked element

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>

Note: I know how to do it using s:checkboxlist but can't here as I need special format in the iteration.


回答1:


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>


来源:https://stackoverflow.com/questions/19159580/how-to-display-pre-checked-checkboxes-inside-iterator-in-struts-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!