How to check list.contains in jsp using struts 2 tags

前端 未结 1 1720
迷失自我
迷失自我 2021-01-22 10:44

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

相关标签:
1条回答
  • 2021-01-22 11:17

    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>
    
    0 讨论(0)
提交回复
热议问题