[英]How to check if List contains the particular element or not in Struts2?
I have tried to check if the List contains particular element or not using Struts 2 in <s:if>
tag? 我试图在
<s:if>
标签中使用Struts 2来检查List是否包含特定元素?
<display:table class="noheader-border" id="data" name="lstAttendance" sort="list"
uid="row" htmlId="sources" export="false">
<display:column style="width:150px">
<s:property value="%{#attr.row.worker.workerName}" />
</display:column>
<display:column style="width:10px;weight:bold;">:</display:column>
<s:if test="lstSalaryDefinedWorkerId.contains(%{#attr.row.workerId})">
...
</s:if>
...
I guess you can do it using OGNL syntax. 我想你可以使用OGNL语法来做到这一点。 For example I have a list and a property in my action class like:
例如,我的动作类中有一个列表和一个属性,如:
private List test;
private String p = "a1";
// And their getters and setters
public String execute() throws Exception {
test = new ArrayList();
test.add("a");
test.add("b");
test.add("c");
test.add("d");
test.add("e");
return SUCCESS;
}
All I need to do following in my JSP page 我需要在JSP页面中执行以下操作
<s:if test="%{p in test}">
Inside If block
</s:if>
<s:else>
Inside Else block
</s:else>
For details refer to the Struts 2 OGNL documentation: 有关详细信息,请参阅Struts 2 OGNL文档:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.