You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Riyad Kalla <rs...@email.arizona.edu> on 2004/06/06 02:15:01 UTC
Taglib: how do you call a method like java.util.List.size() from
the property of a tag?
I'm trying to do something like:
<logic:greaterThan name="userList" property="size" value="20">
<!-- Display paging controls -->
</logic:greaterThan>
but I'm obviously getting an exception on size because it doesn't follow
JB naming conventions. How do I call this method? Do I NEED to use EL
for this?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Taglib: how do you call a method like java.util.List.size() from
the property of a tag?
Posted by Riyad Kalla <rs...@email.arizona.edu>.
Hey Joe that length function looks like just what I wanted....I didn't
want to do scriplets because of the possibility of a NPE if the session
timed out and the list wasn't in the session, I want something that
gracefully handles the missing item and I thought a custom taglib might
be overkill.
Thanks for your suggestions!
Joe Germuska wrote:
> At 5:15 PM -0700 6/5/04, Riyad Kalla wrote:
>
>> I'm trying to do something like:
>> <logic:greaterThan name="userList" property="size" value="20">
>> <!-- Display paging controls -->
>> </logic:greaterThan>
>>
>> but I'm obviously getting an exception on size because it doesn't
>> follow JB naming conventions. How do I call this method? Do I NEED to
>> use EL for this?
>
>
> One of the unfortunate shortcomings of the Collections APIs is the
> lack of a bean-convention-named method to access the length of the list.
>
> If you put userList into the request before forwarding to the JSP, you
> could also set another request attribute with the size value; or you
> could put the list in a simple wrapper:
>
> public class MyListWrapper {
>
> private List list;
> public MyListWrapper(List list) { this.list = list; }
> public int getSize() { return this.list.size(); }
> public List getList() { return this.list; }
> }
>
> If you are using JSTL 1.1, you could use the "length" function.
> http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/fn/length.fn.html
>
> Of course, you could use scriptlets too.
>
> Joe
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Taglib: how do you call a method like java.util.List.size()
from the property of a tag?
Posted by Joe Germuska <Jo...@Germuska.com>.
At 5:15 PM -0700 6/5/04, Riyad Kalla wrote:
>I'm trying to do something like:
><logic:greaterThan name="userList" property="size" value="20">
> <!-- Display paging controls -->
></logic:greaterThan>
>
>but I'm obviously getting an exception on size because it doesn't
>follow JB naming conventions. How do I call this method? Do I NEED
>to use EL for this?
One of the unfortunate shortcomings of the Collections APIs is the
lack of a bean-convention-named method to access the length of the
list.
If you put userList into the request before forwarding to the JSP,
you could also set another request attribute with the size value; or
you could put the list in a simple wrapper:
public class MyListWrapper {
private List list;
public MyListWrapper(List list) { this.list = list; }
public int getSize() { return this.list.size(); }
public List getList() { return this.list; }
}
If you are using JSTL 1.1, you could use the "length" function.
http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/fn/length.fn.html
Of course, you could use scriptlets too.
Joe
--
Joe Germuska
Joe@Germuska.com
http://blog.germuska.com
"In fact, when I die, if I don't hear 'A Love Supreme,' I'll turn
back; I'll know I'm in the wrong place."
- Carlos Santana
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Taglib: how do you call a method like java.util.List.size() from the property of a tag?
Posted by Deepak <de...@ltp.soft.net>.
You can use <bean-el:size> tag
e.g.
<bean-el:size collection="${myForm.list}" id="listSize"/>
then use <c:if> on "listSize"
----- Original Message -----
From: "Riyad Kalla" <rs...@email.arizona.edu>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Sunday, June 06, 2004 5:45 AM
Subject: Taglib: how do you call a method like java.util.List.size() from the property of a tag?
> I'm trying to do something like:
> <logic:greaterThan name="userList" property="size" value="20">
> <!-- Display paging controls -->
> </logic:greaterThan>
>
>
> but I'm obviously getting an exception on size because it doesn't follow
> JB naming conventions. How do I call this method? Do I NEED to use EL
> for this?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
Re: Taglib: how do you call a method like java.util.List.size() from
the property of a tag?
Posted by Riyad Kalla <rs...@email.arizona.edu>.
Comments below:
>Hi Riyad,
>
>here is a simple example:
>
><bean:size name="userList" id="userListSize"/>
>
>
I feel foolish, this is exactly what I wanted and didn't even see that
in the taglib docs. Thanks a million!
><logic:greaterThan name="userListSize" value="20">
>
></logic:graterThan>
>
>BTW, you are doing a very good job on MyEclipseIDE Team!
>
>
Thank you, I appreciate that. They are a great/strong team to work with.
Best,
Riyad
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Taglib: how do you call a method like java.util.List.size() from the property of a tag?
Posted by Henrique VIECILI <vi...@softplan.com.br>.
Hi Riyad,
here is a simple example:
<bean:size name="userList" id="userListSize"/>
<logic:greaterThan name="userListSize" value="20">
</logic:graterThan>
BTW, you are doing a very good job on MyEclipseIDE Team!
Henrique Viecili
----- Original Message -----
From: Riyad Kalla
To: Struts Users Mailing List
Sent: Saturday, June 05, 2004 9:15 PM
Subject: Taglib: how do you call a method like java.util.List.size() from the property of a tag?
I'm trying to do something like:
<logic:greaterThan name="userList" property="size" value="20">
<!-- Display paging controls -->
</logic:greaterThan>
but I'm obviously getting an exception on size because it doesn't follow
JB naming conventions. How do I call this method? Do I NEED to use EL
for this?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org