You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Joe Germuska <Jo...@Germuska.com> on 2004/06/06 16:08:00 UTC

Re: Taglib: how do you call a method like java.util.List.size() from the property of a tag?

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 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