I need to show a series of check boxes and if a condition is succeeded, I need to check them. Below is my code. I have regions which is a hashmap and SelectedRegions which is
There are really many ways to do this. You should also check out the <s:checkbox/>
and <s:checkboxlist/>
tags;
Also note that to follow DRY, you could put the <s:if>
around the checked="checked"
part only, since all the rest is the same.
Keeping it simple, with your code as-is, one way consists in using OGNL's in
(contains) and OGNL's {}
(list projection) like follows:
<s:iterator value="regions">
<li>
<div class="listClass">
<input type = "checkbox"
id = "myTheater"
<s:if test="%{value in selectedRegions.{value}}">
checked = "checked"
</s:if>
name = "theaterCheckBox"
class = "theaterCheckBox" />
<s:property value="value" />
</div>
<div class="checkboxDiv">
<input type="checkbox" id="allFeatured" class="featuredCheckBox" />
</div>
</li>
</s:iterator>