RE: [OT] Getting a Collection's size in JSTL

2002-10-30 Thread Karr, David
 -Original Message-
 From: David Graham [mailto:dgraham1980;hotmail.com]
 Sent: Wednesday, October 30, 2002 8:14 AM
 
 Sorry for the OT post but the java forum was unresponsive.  
 How do you get 
 the size of a collection class in the JSTL EL?
 
 You can do it with jsp expressions like:
 %= collection.size() %
 
 but I want to do something like
 
 c:if test=${collection.size  0}
 
 I've tried every variation on that syntax that I could think of.

That's because you can't do it.  I know, I went through the exact same
discovery process.

If you're using Struts, you can just use bean:size.

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




RE: [OT] Getting a Collection's size in JSTL

2002-10-30 Thread David Graham
Thanks David.  Do you really think I'm not using struts :-) ?

Dave





From: Karr, David [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: 'Struts Users Mailing List' [EMAIL PROTECTED]
Subject: RE: [OT] Getting a Collection's size in JSTL
Date: Wed, 30 Oct 2002 11:18:48 -0500

 -Original Message-
 From: David Graham [mailto:dgraham1980;hotmail.com]
 Sent: Wednesday, October 30, 2002 8:14 AM

 Sorry for the OT post but the java forum was unresponsive.
 How do you get
 the size of a collection class in the JSTL EL?

 You can do it with jsp expressions like:
 %= collection.size() %

 but I want to do something like

 c:if test=${collection.size  0}

 I've tried every variation on that syntax that I could think of.

That's because you can't do it.  I know, I went through the exact same
discovery process.

If you're using Struts, you can just use bean:size.

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


_
Surf the Web without missing calls! Get MSN Broadband.  
http://resourcecenter.msn.com/access/plans/freeactivation.asp


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



RE: [OT] Getting a Collection's size in JSTL

2002-10-30 Thread Karr, David
Well, for a second I thought maybe you were possessed or something :) .

 -Original Message-
 From: David Graham [mailto:dgraham1980;hotmail.com]
 Sent: Wednesday, October 30, 2002 8:24 AM
 To: [EMAIL PROTECTED]
 Subject: RE: [OT] Getting a Collection's size in JSTL
 
 
 Thanks David.  Do you really think I'm not using struts :-) ?
 
 Dave
 
 From: Karr, David [EMAIL PROTECTED]
 Reply-To: Struts Users Mailing List 
 [EMAIL PROTECTED]
 To: 'Struts Users Mailing List' [EMAIL PROTECTED]
 Subject: RE: [OT] Getting a Collection's size in JSTL
 Date: Wed, 30 Oct 2002 11:18:48 -0500
 
   -Original Message-
   From: David Graham [mailto:dgraham1980;hotmail.com]
   Sent: Wednesday, October 30, 2002 8:14 AM
  
   Sorry for the OT post but the java forum was unresponsive.
   How do you get
   the size of a collection class in the JSTL EL?
  
   You can do it with jsp expressions like:
   %= collection.size() %
  
   but I want to do something like
  
   c:if test=${collection.size  0}
  
   I've tried every variation on that syntax that I could think of.
 
 That's because you can't do it.  I know, I went through the 
 exact same
 discovery process.
 
 If you're using Struts, you can just use bean:size.
 
 --
 To unsubscribe, e-mail:   
 mailto:struts-user-unsubscribe;jakarta.apache.org
 For additional commands, e-mail: 
 mailto:struts-user-help;jakarta.apache.org
 
 
 _
 Surf the Web without missing calls! Get MSN Broadband.  
 http://resourcecenter.msn.com/access/plans/freeactivation.asp
 
 
 --
 To unsubscribe, e-mail:   
mailto:struts-user-unsubscribe;jakarta.apache.org
For additional commands, e-mail:
mailto:struts-user-help;jakarta.apache.org

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




Re: [OT] Getting a Collection's size in JSTL

2002-10-30 Thread Craig R. McClanahan


On Wed, 30 Oct 2002, David Graham wrote:

 Date: Wed, 30 Oct 2002 09:13:49 -0700
 From: David Graham [EMAIL PROTECTED]
 Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: [OT] Getting a Collection's size in JSTL

 Sorry for the OT post but the java forum was unresponsive.  How do you get
 the size of a collection class in the JSTL EL?

 You can do it with jsp expressions like:
 %= collection.size() %

 but I want to do something like

 c:if test=${collection.size  0}


This does not work because the size() method does not follow the naming
pattern required for JavaBean properties (where it would be getSize()).

One option would be to make yourself a subclass of things like ArrayList
that simply delegated everything, but added a getSize() method that calls
size() under the covers.

 I've tried every variation on that syntax that I could think of.

 Thanks,
 David


Craig


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




Re: [OT] Getting a Collection's size in JSTL

2002-10-30 Thread David Graham
Thanks Craig.  I realize that it doesn't work because of the naming issue 
but I was wondering if there was an easy way around it.  Subclassing is 
certainly an option, would this be a useful method to add to the commons 
FastArrayList?

Dave






From: Craig R. McClanahan [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: Re: [OT] Getting a Collection's size in JSTL
Date: Wed, 30 Oct 2002 09:40:10 -0800 (PST)



On Wed, 30 Oct 2002, David Graham wrote:

 Date: Wed, 30 Oct 2002 09:13:49 -0700
 From: David Graham [EMAIL PROTECTED]
 Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: [OT] Getting a Collection's size in JSTL

 Sorry for the OT post but the java forum was unresponsive.  How do you 
get
 the size of a collection class in the JSTL EL?

 You can do it with jsp expressions like:
 %= collection.size() %

 but I want to do something like

 c:if test=${collection.size  0}


This does not work because the size() method does not follow the naming
pattern required for JavaBean properties (where it would be getSize()).

One option would be to make yourself a subclass of things like ArrayList
that simply delegated everything, but added a getSize() method that calls
size() under the covers.

 I've tried every variation on that syntax that I could think of.

 Thanks,
 David


Craig


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


_
Surf the Web without missing calls! Get MSN Broadband. 
http://resourcecenter.msn.com/access/plans/freeactivation.asp


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



Re: [OT] Getting a Collection's size in JSTL

2002-10-30 Thread David Graham
I actually thought of a better idea which is getting into commons 
collections territory but I'll post a quick description here.  I made a 
JstlCollectionWrapper class that wraps any Collection object and implements 
the Collection interface.  I added a getSize() method to this class.  The 
business layer classes can return standard Java collections like ArrayList 
and you can wrap them in this class when using them in JSTL.

A similar approach could be taken with the Map interface.  I wish they would 
just add getSize to the standard classes :-(.

David






From: David Graham [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Re: [OT] Getting a Collection's size in JSTL
Date: Wed, 30 Oct 2002 11:13:53 -0700

Thanks Craig.  I realize that it doesn't work because of the naming issue 
but I was wondering if there was an easy way around it.  Subclassing is 
certainly an option, would this be a useful method to add to the commons 
FastArrayList?

Dave






From: Craig R. McClanahan [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: Re: [OT] Getting a Collection's size in JSTL
Date: Wed, 30 Oct 2002 09:40:10 -0800 (PST)



On Wed, 30 Oct 2002, David Graham wrote:

 Date: Wed, 30 Oct 2002 09:13:49 -0700
 From: David Graham [EMAIL PROTECTED]
 Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: [OT] Getting a Collection's size in JSTL

 Sorry for the OT post but the java forum was unresponsive.  How do you 
get
 the size of a collection class in the JSTL EL?

 You can do it with jsp expressions like:
 %= collection.size() %

 but I want to do something like

 c:if test=${collection.size  0}


This does not work because the size() method does not follow the naming
pattern required for JavaBean properties (where it would be getSize()).

One option would be to make yourself a subclass of things like ArrayList
that simply delegated everything, but added a getSize() method that calls
size() under the covers.

 I've tried every variation on that syntax that I could think of.

 Thanks,
 David


Craig


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


_
Surf the Web without missing calls! Get MSN Broadband. 
http://resourcecenter.msn.com/access/plans/freeactivation.asp


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


_
Get a speedy connection with MSN Broadband.  Join now! 
http://resourcecenter.msn.com/access/plans/freeactivation.asp


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



Re: [OT] Getting a Collection's size in JSTL

2002-10-30 Thread Kris Schneider
It should also be relatively painless to use a composition/delegation approach.

public class CollectionBean {

  private Collection c;

  public int getSize() {
return this.c.size();
  }

  public void setCollection(Collection c) {
this.c = c;
  }

  public Collection getCollection() {
return this.c;
  }
}

jsp:useBean id=collBean class=com.foo.CollectionBean/
c:set target=${collBean}
   property=collection
   value=${requestScope.theCollection}/
c:out value=${collBean.size}/

Or something along those lines. Of course, you could completely set up the 
collection bean prior to hitting the JSP as well.

Quoting David Graham [EMAIL PROTECTED]:

 I actually thought of a better idea which is getting into commons 
 collections territory but I'll post a quick description here.  I made a 
 JstlCollectionWrapper class that wraps any Collection object and implements
 
 the Collection interface.  I added a getSize() method to this class.  The 
 business layer classes can return standard Java collections like ArrayList 
 and you can wrap them in this class when using them in JSTL.
 
 A similar approach could be taken with the Map interface.  I wish they would
 
 just add getSize to the standard classes :-(.
 
 David

-- 
Kris Schneider mailto:kris;dotech.com
D.O.Tech   http://www.dotech.com/

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




Re: [OT] Getting a Collection's size in JSTL

2002-10-30 Thread David Graham
That's pretty much what I did except you can only set the internal 
collection in the constructor.  It's an elegant solution that should 
probably (in some form) be included in a larger library.

David






From: Kris Schneider [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: Re: [OT] Getting a Collection's size in JSTL
Date: Wed, 30 Oct 2002 15:30:13 -0500

It should also be relatively painless to use a composition/delegation 
approach.

public class CollectionBean {

  private Collection c;

  public int getSize() {
return this.c.size();
  }

  public void setCollection(Collection c) {
this.c = c;
  }

  public Collection getCollection() {
return this.c;
  }
}

jsp:useBean id=collBean class=com.foo.CollectionBean/
c:set target=${collBean}
   property=collection
   value=${requestScope.theCollection}/
c:out value=${collBean.size}/

Or something along those lines. Of course, you could completely set up the
collection bean prior to hitting the JSP as well.

Quoting David Graham [EMAIL PROTECTED]:

 I actually thought of a better idea which is getting into commons
 collections territory but I'll post a quick description here.  I made a
 JstlCollectionWrapper class that wraps any Collection object and 
implements

 the Collection interface.  I added a getSize() method to this class.  
The
 business layer classes can return standard Java collections like 
ArrayList
 and you can wrap them in this class when using them in JSTL.

 A similar approach could be taken with the Map interface.  I wish they 
would

 just add getSize to the standard classes :-(.

 David

--
Kris Schneider mailto:kris;dotech.com
D.O.Tech   http://www.dotech.com/

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


_
Protect your PC - get McAfee.com VirusScan Online 
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


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



RE: [OT] Getting a Collection's size in JSTL

2002-10-30 Thread Kevin A. Smith
This also seems like a good place to use a DynamicProxy. Since most all of the Java 
Collections package is interfaced base, this seems like it might be an elegant 
solution.

--Kevin

-Original Message-
From: David Graham [mailto:dgraham1980;hotmail.com]
Sent: Wednesday, October 30, 2002 3:44 PM
To: [EMAIL PROTECTED]
Subject: Re: [OT] Getting a Collection's size in JSTL


That's pretty much what I did except you can only set the internal 
collection in the constructor.  It's an elegant solution that should 
probably (in some form) be included in a larger library.

David






From: Kris Schneider [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: Re: [OT] Getting a Collection's size in JSTL
Date: Wed, 30 Oct 2002 15:30:13 -0500

It should also be relatively painless to use a composition/delegation 
approach.

public class CollectionBean {

   private Collection c;

   public int getSize() {
 return this.c.size();
   }

   public void setCollection(Collection c) {
 this.c = c;
   }

   public Collection getCollection() {
 return this.c;
   }
}

jsp:useBean id=collBean class=com.foo.CollectionBean/
c:set target=${collBean}
property=collection
value=${requestScope.theCollection}/
c:out value=${collBean.size}/

Or something along those lines. Of course, you could completely set up the
collection bean prior to hitting the JSP as well.

Quoting David Graham [EMAIL PROTECTED]:

  I actually thought of a better idea which is getting into commons
  collections territory but I'll post a quick description here.  I made a
  JstlCollectionWrapper class that wraps any Collection object and 
implements
 
  the Collection interface.  I added a getSize() method to this class.  
The
  business layer classes can return standard Java collections like 
ArrayList
  and you can wrap them in this class when using them in JSTL.
 
  A similar approach could be taken with the Map interface.  I wish they 
would
 
  just add getSize to the standard classes :-(.
 
  David

--
Kris Schneider mailto:kris;dotech.com
D.O.Tech   http://www.dotech.com/

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


_
Protect your PC - get McAfee.com VirusScan Online 
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


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


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




RE: [OT] Getting a Collection's size in JSTL

2002-10-30 Thread David Graham
What is a DynamicProxy?  We may be talking about the same pattern with 
different names.

David






From: Kevin A. Smith [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: RE: [OT] Getting a Collection's size in JSTL
Date: Wed, 30 Oct 2002 16:31:03 -0500

This also seems like a good place to use a DynamicProxy. Since most all of 
the Java Collections package is interfaced base, this seems like it might 
be an elegant solution.

--Kevin

-Original Message-
From: David Graham [mailto:dgraham1980;hotmail.com]
Sent: Wednesday, October 30, 2002 3:44 PM
To: [EMAIL PROTECTED]
Subject: Re: [OT] Getting a Collection's size in JSTL


That's pretty much what I did except you can only set the internal
collection in the constructor.  It's an elegant solution that should
probably (in some form) be included in a larger library.

David






From: Kris Schneider [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: Re: [OT] Getting a Collection's size in JSTL
Date: Wed, 30 Oct 2002 15:30:13 -0500

It should also be relatively painless to use a composition/delegation
approach.

public class CollectionBean {

   private Collection c;

   public int getSize() {
 return this.c.size();
   }

   public void setCollection(Collection c) {
 this.c = c;
   }

   public Collection getCollection() {
 return this.c;
   }
}

jsp:useBean id=collBean class=com.foo.CollectionBean/
c:set target=${collBean}
property=collection
value=${requestScope.theCollection}/
c:out value=${collBean.size}/

Or something along those lines. Of course, you could completely set up 
the
collection bean prior to hitting the JSP as well.

Quoting David Graham [EMAIL PROTECTED]:

  I actually thought of a better idea which is getting into commons
  collections territory but I'll post a quick description here.  I made 
a
  JstlCollectionWrapper class that wraps any Collection object and
implements
 
  the Collection interface.  I added a getSize() method to this class.
The
  business layer classes can return standard Java collections like
ArrayList
  and you can wrap them in this class when using them in JSTL.
 
  A similar approach could be taken with the Map interface.  I wish they
would
 
  just add getSize to the standard classes :-(.
 
  David

--
Kris Schneider mailto:kris;dotech.com
D.O.Tech   http://www.dotech.com/

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


_
Protect your PC - get McAfee.com VirusScan Online
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


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


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


_
Unlimited Internet access for only $21.95/month.  Try MSN! 
http://resourcecenter.msn.com/access/plans/2monthsfree.asp


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



RE: [OT] Getting a Collection's size in JSTL

2002-10-30 Thread Kevin A. Smith
I'm referring to the java.lang.reflect.InvocationHandler. You can use it create proxy 
objects for interfaces on-the-fly. I've used it extensively as a way of adapting 
mismatched interfaces between objects.

--Kevin

-Original Message-
From: David Graham [mailto:dgraham1980;hotmail.com]
Sent: Wednesday, October 30, 2002 4:35 PM
To: [EMAIL PROTECTED]
Subject: RE: [OT] Getting a Collection's size in JSTL


What is a DynamicProxy?  We may be talking about the same pattern with 
different names.

David






From: Kevin A. Smith [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: RE: [OT] Getting a Collection's size in JSTL
Date: Wed, 30 Oct 2002 16:31:03 -0500

This also seems like a good place to use a DynamicProxy. Since most all of 
the Java Collections package is interfaced base, this seems like it might 
be an elegant solution.

--Kevin

-Original Message-
From: David Graham [mailto:dgraham1980;hotmail.com]
Sent: Wednesday, October 30, 2002 3:44 PM
To: [EMAIL PROTECTED]
Subject: Re: [OT] Getting a Collection's size in JSTL


That's pretty much what I did except you can only set the internal
collection in the constructor.  It's an elegant solution that should
probably (in some form) be included in a larger library.

David






 From: Kris Schneider [EMAIL PROTECTED]
 Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
 To: Struts Users Mailing List [EMAIL PROTECTED]
 Subject: Re: [OT] Getting a Collection's size in JSTL
 Date: Wed, 30 Oct 2002 15:30:13 -0500
 
 It should also be relatively painless to use a composition/delegation
 approach.
 
 public class CollectionBean {
 
private Collection c;
 
public int getSize() {
  return this.c.size();
}
 
public void setCollection(Collection c) {
  this.c = c;
}
 
public Collection getCollection() {
  return this.c;
}
 }
 
 jsp:useBean id=collBean class=com.foo.CollectionBean/
 c:set target=${collBean}
 property=collection
 value=${requestScope.theCollection}/
 c:out value=${collBean.size}/
 
 Or something along those lines. Of course, you could completely set up 
the
 collection bean prior to hitting the JSP as well.
 
 Quoting David Graham [EMAIL PROTECTED]:
 
   I actually thought of a better idea which is getting into commons
   collections territory but I'll post a quick description here.  I made 
a
   JstlCollectionWrapper class that wraps any Collection object and
 implements
  
   the Collection interface.  I added a getSize() method to this class.
 The
   business layer classes can return standard Java collections like
 ArrayList
   and you can wrap them in this class when using them in JSTL.
  
   A similar approach could be taken with the Map interface.  I wish they
 would
  
   just add getSize to the standard classes :-(.
  
   David
 
 --
 Kris Schneider mailto:kris;dotech.com
 D.O.Tech   http://www.dotech.com/
 
 --
 To unsubscribe, e-mail:
 mailto:struts-user-unsubscribe;jakarta.apache.org
 For additional commands, e-mail:
 mailto:struts-user-help;jakarta.apache.org


_
Protect your PC - get McAfee.com VirusScan Online
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


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


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


_
Unlimited Internet access for only $21.95/month.  Try MSN! 
http://resourcecenter.msn.com/access/plans/2monthsfree.asp


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


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




RE: [OT] Getting a Collection's size in JSTL

2002-10-30 Thread David Graham
Cool, I'll look into it.

Thanks,
David







From: Kevin A. Smith [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: RE: [OT] Getting a Collection's size in JSTL
Date: Wed, 30 Oct 2002 16:39:27 -0500

I'm referring to the java.lang.reflect.InvocationHandler. You can use it 
create proxy objects for interfaces on-the-fly. I've used it extensively 
as a way of adapting mismatched interfaces between objects.

--Kevin

-Original Message-
From: David Graham [mailto:dgraham1980;hotmail.com]
Sent: Wednesday, October 30, 2002 4:35 PM
To: [EMAIL PROTECTED]
Subject: RE: [OT] Getting a Collection's size in JSTL


What is a DynamicProxy?  We may be talking about the same pattern with
different names.

David






From: Kevin A. Smith [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: RE: [OT] Getting a Collection's size in JSTL
Date: Wed, 30 Oct 2002 16:31:03 -0500

This also seems like a good place to use a DynamicProxy. Since most all 
of
the Java Collections package is interfaced base, this seems like it might
be an elegant solution.

--Kevin

-Original Message-
From: David Graham [mailto:dgraham1980;hotmail.com]
Sent: Wednesday, October 30, 2002 3:44 PM
To: [EMAIL PROTECTED]
Subject: Re: [OT] Getting a Collection's size in JSTL


That's pretty much what I did except you can only set the internal
collection in the constructor.  It's an elegant solution that should
probably (in some form) be included in a larger library.

David






 From: Kris Schneider [EMAIL PROTECTED]
 Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
 To: Struts Users Mailing List [EMAIL PROTECTED]
 Subject: Re: [OT] Getting a Collection's size in JSTL
 Date: Wed, 30 Oct 2002 15:30:13 -0500
 
 It should also be relatively painless to use a composition/delegation
 approach.
 
 public class CollectionBean {
 
private Collection c;
 
public int getSize() {
  return this.c.size();
}
 
public void setCollection(Collection c) {
  this.c = c;
}
 
public Collection getCollection() {
  return this.c;
}
 }
 
 jsp:useBean id=collBean class=com.foo.CollectionBean/
 c:set target=${collBean}
 property=collection
 value=${requestScope.theCollection}/
 c:out value=${collBean.size}/
 
 Or something along those lines. Of course, you could completely set up
the
 collection bean prior to hitting the JSP as well.
 
 Quoting David Graham [EMAIL PROTECTED]:
 
   I actually thought of a better idea which is getting into commons
   collections territory but I'll post a quick description here.  I 
made
a
   JstlCollectionWrapper class that wraps any Collection object and
 implements
  
   the Collection interface.  I added a getSize() method to this class.
 The
   business layer classes can return standard Java collections like
 ArrayList
   and you can wrap them in this class when using them in JSTL.
  
   A similar approach could be taken with the Map interface.  I wish 
they
 would
  
   just add getSize to the standard classes :-(.
  
   David
 
 --
 Kris Schneider mailto:kris;dotech.com
 D.O.Tech   http://www.dotech.com/
 
 --
 To unsubscribe, e-mail:
 mailto:struts-user-unsubscribe;jakarta.apache.org
 For additional commands, e-mail:
 mailto:struts-user-help;jakarta.apache.org


_
Protect your PC - get McAfee.com VirusScan Online
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


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


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


_
Unlimited Internet access for only $21.95/month.  Try MSN!
http://resourcecenter.msn.com/access/plans/2monthsfree.asp


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


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


_
Broadband? Dial-up? Get reliable MSN Internet Access. 
http://resourcecenter.msn.com/access/plans/default.asp


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



RE: [OT] Getting a Collection's size in JSTL

2002-10-30 Thread Kris Schneider
But applying a proxy to this scenario seems like overkill. Wouldn't you have to 
do something like the following:

public interface CollectionInfo {
  public int getSize();
}

public class CollectionHandler implements InvocationHandler {

  private Collection c;

  public CollectionHandler(Collection c) {
this.c = c;
  }

  public Object invoke(Object proxy,
   Method method,
   Object[] args) throws Throwable {
if (getSize.equals(method.getName())) {
  return new Integer(this.c.size());
} else {
  return method.invoke(this.c, args);
}
  }
}

InvocationHandler handler = new CollectionHandler(theCollection);
Object proxy = Proxy.newProxyInstance(classLoader,
  new Class[] { Collection.class,
CollectionInfo.class },
  handler);
request.setAttribute(collectionProxy, proxy);

Which may not be horrible if you're using a servlet or Action, but how would 
you use it in a JSP-only situation?

Quoting Kevin A. Smith [EMAIL PROTECTED]:

 I'm referring to the java.lang.reflect.InvocationHandler. You can use it
 create proxy objects for interfaces on-the-fly. I've used it extensively as
 a way of adapting mismatched interfaces between objects.
 
 --Kevin
 
 -Original Message-
 From: David Graham [mailto:dgraham1980;hotmail.com]
 Sent: Wednesday, October 30, 2002 4:35 PM
 To: [EMAIL PROTECTED]
 Subject: RE: [OT] Getting a Collection's size in JSTL
 
 
 What is a DynamicProxy?  We may be talking about the same pattern with 
 different names.
 
 David
 
 
 
 
 
 
 From: Kevin A. Smith [EMAIL PROTECTED]
 Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
 To: Struts Users Mailing List [EMAIL PROTECTED]
 Subject: RE: [OT] Getting a Collection's size in JSTL
 Date: Wed, 30 Oct 2002 16:31:03 -0500
 
 This also seems like a good place to use a DynamicProxy. Since most all of
 
 the Java Collections package is interfaced base, this seems like it might 
 be an elegant solution.
 
 --Kevin
 
 -Original Message-
 From: David Graham [mailto:dgraham1980;hotmail.com]
 Sent: Wednesday, October 30, 2002 3:44 PM
 To: [EMAIL PROTECTED]
 Subject: Re: [OT] Getting a Collection's size in JSTL
 
 
 That's pretty much what I did except you can only set the internal
 collection in the constructor.  It's an elegant solution that should
 probably (in some form) be included in a larger library.
 
 David
 
 
 
 
 
 
  From: Kris Schneider [EMAIL PROTECTED]
  Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
  To: Struts Users Mailing List [EMAIL PROTECTED]
  Subject: Re: [OT] Getting a Collection's size in JSTL
  Date: Wed, 30 Oct 2002 15:30:13 -0500
  
  It should also be relatively painless to use a composition/delegation
  approach.
  
  public class CollectionBean {
  
 private Collection c;
  
 public int getSize() {
   return this.c.size();
 }
  
 public void setCollection(Collection c) {
   this.c = c;
 }
  
 public Collection getCollection() {
   return this.c;
 }
  }
  
  jsp:useBean id=collBean class=com.foo.CollectionBean/
  c:set target=${collBean}
  property=collection
  value=${requestScope.theCollection}/
  c:out value=${collBean.size}/
  
  Or something along those lines. Of course, you could completely set up 
 the
  collection bean prior to hitting the JSP as well.
  
  Quoting David Graham [EMAIL PROTECTED]:
  
I actually thought of a better idea which is getting into commons
collections territory but I'll post a quick description here.  I made
 
 a
JstlCollectionWrapper class that wraps any Collection object and
  implements
   
the Collection interface.  I added a getSize() method to this class.
  The
business layer classes can return standard Java collections like
  ArrayList
and you can wrap them in this class when using them in JSTL.
   
A similar approach could be taken with the Map interface.  I wish
 they
  would
   
just add getSize to the standard classes :-(.
   
David
  
  --
  Kris Schneider mailto:kris;dotech.com
  D.O.Tech   http://www.dotech.com/
  
  --
  To unsubscribe, e-mail:
  mailto:struts-user-unsubscribe;jakarta.apache.org
  For additional commands, e-mail:
  mailto:struts-user-help;jakarta.apache.org
 
 
 _
 Protect your PC - get McAfee.com VirusScan Online
 http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
 
 
 --
 To unsubscribe, e-mail:   
 mailto:struts-user-unsubscribe;jakarta.apache.org
 For additional commands, e-mail: 
 mailto:struts-user-help;jakarta.apache.org
 
 
 --
 To unsubscribe, e-mail:   
 mailto:struts-user-unsubscribe;jakarta.apache.org
 For additional commands, e-mail: 
 mailto:struts-user-help;jakarta.apache.org
 
 
 _
 Unlimited Internet access

RE: [OT] Getting a Collection's size in JSTL

2002-10-30 Thread Kevin A. Smith
I would use a factory to create the proxies. This would occur inside of the Struts 
action. Then, in the JSP, you could access the collections as you normally would.

--Kevin

-Original Message-
From: Kris Schneider [mailto:kris;dotech.com]
Sent: Wednesday, October 30, 2002 4:57 PM
To: Struts Users Mailing List
Subject: RE: [OT] Getting a Collection's size in JSTL


But applying a proxy to this scenario seems like overkill. Wouldn't you have to 
do something like the following:

public interface CollectionInfo {
  public int getSize();
}

public class CollectionHandler implements InvocationHandler {

  private Collection c;

  public CollectionHandler(Collection c) {
this.c = c;
  }

  public Object invoke(Object proxy,
   Method method,
   Object[] args) throws Throwable {
if (getSize.equals(method.getName())) {
  return new Integer(this.c.size());
} else {
  return method.invoke(this.c, args);
}
  }
}

InvocationHandler handler = new CollectionHandler(theCollection);
Object proxy = Proxy.newProxyInstance(classLoader,
  new Class[] { Collection.class,
CollectionInfo.class },
  handler);
request.setAttribute(collectionProxy, proxy);

Which may not be horrible if you're using a servlet or Action, but how would 
you use it in a JSP-only situation?

Quoting Kevin A. Smith [EMAIL PROTECTED]:

 I'm referring to the java.lang.reflect.InvocationHandler. You can use it
 create proxy objects for interfaces on-the-fly. I've used it extensively as
 a way of adapting mismatched interfaces between objects.
 
 --Kevin
 
 -Original Message-
 From: David Graham [mailto:dgraham1980;hotmail.com]
 Sent: Wednesday, October 30, 2002 4:35 PM
 To: [EMAIL PROTECTED]
 Subject: RE: [OT] Getting a Collection's size in JSTL
 
 
 What is a DynamicProxy?  We may be talking about the same pattern with 
 different names.
 
 David
 
 
 
 
 
 
 From: Kevin A. Smith [EMAIL PROTECTED]
 Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
 To: Struts Users Mailing List [EMAIL PROTECTED]
 Subject: RE: [OT] Getting a Collection's size in JSTL
 Date: Wed, 30 Oct 2002 16:31:03 -0500
 
 This also seems like a good place to use a DynamicProxy. Since most all of
 
 the Java Collections package is interfaced base, this seems like it might 
 be an elegant solution.
 
 --Kevin
 
 -Original Message-
 From: David Graham [mailto:dgraham1980;hotmail.com]
 Sent: Wednesday, October 30, 2002 3:44 PM
 To: [EMAIL PROTECTED]
 Subject: Re: [OT] Getting a Collection's size in JSTL
 
 
 That's pretty much what I did except you can only set the internal
 collection in the constructor.  It's an elegant solution that should
 probably (in some form) be included in a larger library.
 
 David
 
 
 
 
 
 
  From: Kris Schneider [EMAIL PROTECTED]
  Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
  To: Struts Users Mailing List [EMAIL PROTECTED]
  Subject: Re: [OT] Getting a Collection's size in JSTL
  Date: Wed, 30 Oct 2002 15:30:13 -0500
  
  It should also be relatively painless to use a composition/delegation
  approach.
  
  public class CollectionBean {
  
 private Collection c;
  
 public int getSize() {
   return this.c.size();
 }
  
 public void setCollection(Collection c) {
   this.c = c;
 }
  
 public Collection getCollection() {
   return this.c;
 }
  }
  
  jsp:useBean id=collBean class=com.foo.CollectionBean/
  c:set target=${collBean}
  property=collection
  value=${requestScope.theCollection}/
  c:out value=${collBean.size}/
  
  Or something along those lines. Of course, you could completely set up 
 the
  collection bean prior to hitting the JSP as well.
  
  Quoting David Graham [EMAIL PROTECTED]:
  
I actually thought of a better idea which is getting into commons
collections territory but I'll post a quick description here.  I made
 
 a
JstlCollectionWrapper class that wraps any Collection object and
  implements
   
the Collection interface.  I added a getSize() method to this class.
  The
business layer classes can return standard Java collections like
  ArrayList
and you can wrap them in this class when using them in JSTL.
   
A similar approach could be taken with the Map interface.  I wish
 they
  would
   
just add getSize to the standard classes :-(.
   
David
  
  --
  Kris Schneider mailto:kris;dotech.com
  D.O.Tech   http://www.dotech.com/
  
  --
  To unsubscribe, e-mail:
  mailto:struts-user-unsubscribe;jakarta.apache.org
  For additional commands, e-mail:
  mailto:struts-user-help;jakarta.apache.org
 
 
 _
 Protect your PC - get McAfee.com VirusScan Online
 http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
 
 
 --
 To unsubscribe, e-mail:   
 mailto:struts