问题
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