You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by fergunet <fe...@hotmail.com> on 2007/08/13 13:06:08 UTC

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

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.
-- 
View this message in context: http://www.nabble.com/How-to-know-if-an-element-of-a-list-belongs-to-another-list-using-Struts2-tags--tf4260538.html#a12124300
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


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

Posted by fergunet <fe...@hotmail.com>.
Well it's more complicated than that, I guess. Exactly is to compare two ID
attribute between two objects (the rest of the attributes may be different),
so I'm thinking in create the external OGNL variable and set it to "true"
when the element is found (as I said in my previous post).

...

Ok. Finally I've made it! : ) But every time I want to modify an OGNL
variable I have to create an <s:if test=%{#variable=value}> tag. Is it
correct? How can I operate with OGNL variables without using this tag?

BTW thank you for your response Laurie, I've wrote it in my magic diary ;) 

Laurie Harper wrote:
> 
> 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@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-know-if-an-element-of-a-list-belongs-to-another-list-using-Struts2-tags--tf4260538.html#a12178014
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


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

Posted by Laurie Harper <la...@holoweb.net>.
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@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org