如何使用struts 2标签检查jsp中的list.contains [英] How to check list.contains in jsp using struts 2 tags

查看:384
本文介绍了如何使用struts 2标签检查jsp中的list.contains的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示一系列复选框,如果条件成功,我需要检查它们。以下是我的代码。我有一个区域是一个hashmap和SelectedRegions是一个数组列表。我正在迭代我的区域地图,并在其旁边显示带有文本的复选框作为我的区域地图中的值。现在,在迭代时,如果数组列表中有区域映射的值,我需要选中复选框。别检查。我尝试过如下所示的那个。但是它没有用。

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 an array list. I am iterating over my regions map, and displaying checkboxes with text next to it as the value from my regions map. Now, while iterating, if the value of regions map is available in the array list, I need to make the check box checked. else Un checked. I tried like the one shown below. But its not working.

<s:iterator value="regions">
    <li>
        <div class="listClass">
            <s:if test="#regions.value==selectedRegions.value">
                <input type="checkbox" id='myTheater' checked="checked" name="theaterCheckBox" class="theaterCheckBox" />
                <s:property value="value" />
            </s:if>
            <s:else>
                <input type="checkbox" id='myTheater' name="theaterCheckBox" class="theaterCheckBox" />
                <s:property value="value" />
            </s:else>
        </div>
        <div class="checkboxDiv">
            <input type="checkbox" id="allFeatured" class="featuredCheckBox" />
        </div>
    </li>
</s:iterator>

如何,我使用的if条件不起作用。你能不能请
让我知道怎么做到这一点?

Some how, the if condition that I am using is not working. Could you please let me know how to attain this?

推荐答案

有真有很多方法可以做到这一点。您还应该查看< s:复选框/> < s:checkboxlist /> 标签;

There are really many ways to do this. You should also check out the <s:checkbox/> and <s:checkboxlist/> tags;

另请注意,要关注DRY,您可以将< s:if> 放在<$附近c $ c> checked =checked仅部分,因为所有其余部分都相同。

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.

保持简单,代码为-is,一种方法是在中使用OGNL的包含)和OGNL的 {} 列表投影)如下所示:

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>

这篇关于如何使用struts 2标签检查jsp中的list.contains的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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