Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check stat.count value in arraylist in <s:iterator> tag for struts 2

Tags:

jsp

struts2

<% System.out.println("These indexed shall be shown on gui "+(ArrayList)request.getSession().getAttribute("selectedIndexes")); %>   // ArrayList value can be 2,3,5,9

  <s:iterator var="itr" value="#session.completeArrayList" status="stat">
 <s:if > //if stat.count value present in arraylist(selectedIndexes), then go to if loop
 </s:if

</s:iterator>

I dont know how to check %{#stat.count} value in arraylist{selectedIndexes} in <s:if> loop. How shall i do this

like image 386
user752590 Avatar asked Dec 28 '12 05:12

user752590


3 Answers

Have you tried index and count property yet. Here is the link that shows example.

  <s:iterator status="status" value='%{0, 1}'>
      Index: <s:property value="%{#status.index}" /> <br />
      Count: <s:property value="%{#status.count}" /> <br />  
   </s:iterator>

will print

Index: 0 Count: 1 Index: 1 Count: 2

like image 139
Akhilesh Avatar answered Nov 06 '22 04:11

Akhilesh


Struts2 uses OGNL and it has in operator. So you can check it easily like that:

<s:iterator var="itr" value="#session.completeArrayList" status="stat">
  <s:if test="#stat.count in #session.selectedIndexes">
  </s:if
</s:iterator>
like image 36
Aleksandr M Avatar answered Nov 06 '22 06:11

Aleksandr M


<s:iterator var="itr" value="#session.completeArrayList" status="stat">
  <s:iterator var="ind" value="#session.selectedIndexes">
    <s:if test="#stat.count == #ind">
      I found #stat.count in selectedIndexes ArrayList
    </s:if>
  </s:iterator>
</s:iterator>
like image 1
Vasily Komarov Avatar answered Nov 06 '22 06:11

Vasily Komarov