You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Firmin David <da...@capco.com> on 2001/04/18 11:17:33 UTC

Using a collection as a bean with the logic tags

Hi all,
I'm having trouble using the logic taglib (specifically
greaterEqual/lessThan) with a bean of type java.util.Map.
I need to do varying logic based on the size of the map, but am having
trouble making the value of .size() available to the tags.
I'd like to do something along these lines, but with as few scriptlets as
possible (I know this won't work):

<jsp:useBean id="items" scope="session" type="java.util.Map"/>
...
...
<logic:greaterEqual property="<%=items.values().size()%>" value="1">
	...
	...stuff
	...
</logic:greaterEqual>
<logic:lessThan property="<%items.values().size()%>" value="1">
	...
	...other stuff
	...
</logic:lessThan>

Like I say, I know what's written above won't work for all the various
reasons, but can anyone suggest something that might?
One idea I had was to use bean:define to open the size up to page scope and
then using the assigned id for it as the property in the logic tags, but I
can't make that work either.

Can anyone help me out?

Thanks in advance

Dave

************************************************************************
The information in this email is confidential and is intended solely
for the addressee(s).
Access to this email by anyone else is unauthorised. If you are not
an intended recipient, you must not read, use or disseminate the
information contained in the email.
Any views expressed in this message are those of the individual
sender, except where the sender specifically states them to be
the views of Capco.

http://www.capco.com
***********************************************************************


RE: getting size of a collection

Posted by Sundaram Ramasamy <su...@percipia.com>.
Thanks, it defined like this

<bean:size name="list"  id="itemsSize" scope="page"/>

its working.


-----Original Message-----
From: 	Jean-Noel Ribette [mailto:jean-noel.ribette@improve.fr]
Sent:	Wednesday, April 18, 2001 9:32 AM
To:	struts-user@jakarta.apache.org
Subject:	Re: getting size of  a collection


----- Original Message -----
From: Sundaram Ramasamy <su...@percipia.com>
To: <st...@jakarta.apache.org>
Sent: Wednesday, April 18, 2001 3:14 PM
Subject: getting size of a collection


> Hi
>
> I have collection like this.
> <%    java.util.ArrayList list = new java.util.ArrayList();
> list.add("First");
> list.add("Second");
> list.add("Third");
> list.add("Fourth");
> list.add("Fifth");
>   pageContext.setAttribute("list", list, PageContext.PAGE_SCOPE);
>  %>
>
>
> Before processing this collection, I want to compare the collection item
> grater than 1. how  will I do this.
>
> Can I use like this.
>
> <bean:size name="list" property="size" id="itemsSize" scope="session"/>

Yes you can, but you don't have to put  " property="size'' ". The tag knows
how to get the size of an Array, a
Collection and a Map.

Jean-Noel


Re: getting size of a collection

Posted by Jean-Noel Ribette <je...@improve.fr>.
----- Original Message -----
From: Sundaram Ramasamy <su...@percipia.com>
To: <st...@jakarta.apache.org>
Sent: Wednesday, April 18, 2001 3:14 PM
Subject: getting size of a collection


> Hi
>
> I have collection like this.
> <%    java.util.ArrayList list = new java.util.ArrayList();
> list.add("First");
> list.add("Second");
> list.add("Third");
> list.add("Fourth");
> list.add("Fifth");
>   pageContext.setAttribute("list", list, PageContext.PAGE_SCOPE);
>  %>
>
>
> Before processing this collection, I want to compare the collection item
> grater than 1. how  will I do this.
>
> Can I use like this.
>
> <bean:size name="list" property="size" id="itemsSize" scope="session"/>

Yes you can, but you don't have to put  " property="size'' ". The tag knows how to get the size of an Array, a
Collection and a Map.

Jean-Noel


getting size of a collection

Posted by Sundaram Ramasamy <su...@percipia.com>.
Hi

I have collection like this.
<%    java.util.ArrayList list = new java.util.ArrayList();
list.add("First");
list.add("Second");
list.add("Third");
list.add("Fourth");
list.add("Fifth");
  pageContext.setAttribute("list", list, PageContext.PAGE_SCOPE);
 %>


Before processing this collection, I want to compare the collection item
grater than 1. how  will I do this.

Can I use like this.

<bean:size name="list" property="size" id="itemsSize" scope="session"/>

Thanks





Re: Using a collection as a bean with the logic tags

Posted by Jean-Noel Ribette <je...@improve.fr>.
It is possible to use the <bean:size> tag to expose the size of a collection:

<bean:size name="items" property="values" id="itemsSize" scope="session"/>
...
...
<logic:greaterEqual name="itemsSize" value="1">
...
...stuff
...
</logic:greaterEqual>
<logic:lessThan name="itemsSize" value="1">
...
...other stuff
...
</logic:lessThan>



Jean-Noel

----- Original Message ----- 
From: Firmin David <da...@capco.com>
To: <st...@jakarta.apache.org>
Sent: Wednesday, April 18, 2001 11:17 AM
Subject: Using a collection as a bean with the logic tags


> Hi all,
> I'm having trouble using the logic taglib (specifically
> greaterEqual/lessThan) with a bean of type java.util.Map.
> I need to do varying logic based on the size of the map, but am having
> trouble making the value of .size() available to the tags.
> I'd like to do something along these lines, but with as few scriptlets as
> possible (I know this won't work):
> 
> <jsp:useBean id="items" scope="session" type="java.util.Map"/>
> ...
> ...
> <logic:greaterEqual property="<%=items.values().size()%>" value="1">
> ...
> ...stuff
> ...
> </logic:greaterEqual>
> <logic:lessThan property="<%items.values().size()%>" value="1">
> ...
> ...other stuff
> ...
> </logic:lessThan>
> 
> Like I say, I know what's written above won't work for all the various
> reasons, but can anyone suggest something that might?
> One idea I had was to use bean:define to open the size up to page scope and
> then using the assigned id for it as the property in the logic tags, but I
> can't make that work either.
> 
> Can anyone help me out?
> 
> Thanks in advance
> 
> Dave
> 
> ************************************************************************
> The information in this email is confidential and is intended solely
> for the addressee(s).
> Access to this email by anyone else is unauthorised. If you are not
> an intended recipient, you must not read, use or disseminate the
> information contained in the email.
> Any views expressed in this message are those of the individual
> sender, except where the sender specifically states them to be
> the views of Capco.
> 
> http://www.capco.com
> ***********************************************************************
> 
>