Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

Re: How to know if an element of a list belongs to another list using
 Struts2 tags?

Laurie Harper

2007-08-13

Replies:

fergunet wrote:
> Hi all! I'm iterating over two list, and I need to shown if an element of the
> second list belongs to the first.
>
> Something like that:
>
> iterator list1
>  print list1.actualElement.attributes...
>  iterator list2
>    if list2.element == list1.actualElement
>       print "yes"
>    else
>       print "no"
>
> The problem is that I only want to print ONE "yes" or "not" not all of them.
> It exists any tag like <s:belongs value="myList" element="theElement"> or
> something? Or I should create an external variable "_belongs" and set to
> true if the element is found (like the standard search procedure we learnt
> years ago when we were rookies in programming ; )
>
> Thank you in advance, and like always, sorry about my English.

Perhaps an OGNL expressionn along the lines of
%{list2.contains(list1_item)} would do what you want. Something like

 <s:if test="%{list2.contains(list1_item)}">
  yes
 </s:if>
 <s:else>
  no
 </s:else>

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.