I have two Set
s
set1 contains(\"A\",\"B\",\"C\",\"D\") elements
set2 contains(\"E\",\"F\",\"D\",\"G\") elements
I want to co
Rearranged to better list the several ways:
With two Iterators:
<s:iterator value="setOne" var="first" status="ctr1">
<s:iterator value="setTwo" var="second" status="ctr2">
<s:if test="%{#first == #second}">
Common value detected : [<s:property value="%{#first}"/>]
<br/> setOne position : [<s:property value="%{#ctr1.index}"/>]
<br/> setTwo position : [<s:property value="%{#ctr2.index}"/>]
<br/>
</s:if>
</s:iterator>
</s:iterator>
With a single Iterator and Set.contains(Object):
<s:iterator value="setOne" var="first" status="ctr1">
<s:if test="%{setTwo.contains('#first')}">
Common value detected : [<s:property value="%{#first}"/>] <br/>
</s:if>
</s:iterator>
With a single Iterator and pure OGNL:
<s:iterator value="setOne" var="first" status="ctr1">
<s:if test="%{#first in setTwo}">
Common value detected : [<s:property value="%{#first}"/>] <br/>
</s:if>
</s:iterator>
Without Iterators, using OGNL List Selection only (thanks to @AleksandrM for the code):
<s:property value="setOne.{? #this in setTwo}"/>
Try the code below:
<s:iterator var="val1" value="set1">
<s:iterator var="val2" value="set2">
<s:if test="#val1 == #val2">
<s:property /><br>
</s:if>
</s:iterator>
</s:iterator>
Try this.i think it will work for you. and if not then do some trial & error on this.
<s:iterator value="set1" var="first">
<s:iterator value="set2" var="second">
<s:set name="valueofset1" value="%{#set1.index}" />
<s:set name="valueOfSet2" value="%{#set2.index}" />
<s:if test="valueofset1 == valueOfSet2">
//Do what ever you want
</s:if>
</s:iterator>
</s:iterator>