How to check if List contains a specific element or not in Struts2?

I tried to check if List contains a specific element or not using Struts 2 in the <s:if> ?

 <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> ... 
+4
source share
1 answer

I think you can do this using OGNL syntax. For example, I have a list and a property in my action class, for example:

 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 on my JSP page

 <s:if test="%{p in test}"> Inside If block </s:if> <s:else> Inside Else block </s:else> 

See the Struts 2 OGNL documentation for more details:

+7
source

Source: https://habr.com/ru/post/1388267/


All Articles