You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Roy Benjamin <Be...@adobe.com> on 2004/03/26 19:09:29 UTC

EL access to a bean property... ?

I am displaying the values in a TreeMap using forEach tag.
However, I only want to do this if the map is not empty.
I also need to display the count of entries in the map at
the top of the page.

In TreeMap, size/size() is not a Bean Property (no?) so I tried
in-line subclassing to expose the property:

<%
  TreeMap treeMap = new TreeMap() {
      public int getSize(){return size();}
    };
  pageContext.setAttribute("TableRows",treeMap);
%>

now much later I try:

<TD>
Search Results:&nbsp;<c:out value="${TableRows.size}"/>&nbsp;found.
</TD>

I could just count things as they are added to the map
over a series of SQL queries, but it seemed to me this
was the better solution.. only the EL expression is null.

I'm sure I'm doing something wrong....

Thanks

Roy


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


Re: EL access to a bean property... ?

Posted by Kris Schneider <kr...@dotech.com>.
Right, because the wrapper would be a JavaBean, not a Map. The gory details
behind the "." operator can be found in section A.3.4 Operators "[]" and "." of
the JSTL 1.0 Spec.

Quoting Roy Benjamin <Be...@adobe.com>:

> Very interesting, so wrapping would work, but you can't
> just expose a Bean property.
> 
> I've switched to c-rt for now, 
> 
> Thanks!
> 
> On Fri, 2004-03-26 at 10:35, Kris Schneider wrote:
> > Maps are treated differently than regular JavaBeans so that you can't
> access
> > bean properties. For example, every object has a bean property called
> "class",
> > but you won't get any output if you try ${map.class}. It's even more fun to
> try
> > and get at a map's "empty" property ;-). If all you're concerned with is
> > testing whether a map is empty or not, you can use ${not empty map}. If
> you
> > really need the size of the map, you could try the Unstandard taglib:
> > 
> > http://jakarta.apache.org/taglibs/sandbox/doc/unstandard-doc/intro.html
> > 
> > Or do something like create a wrapper bean for collections that exposes a
> "size"
> > property and delegates to the wrapped collection.
> > 
> > Quoting Roy Benjamin <Be...@adobe.com>:
> > 
> > > I am displaying the values in a TreeMap using forEach tag.
> > > However, I only want to do this if the map is not empty.
> > > I also need to display the count of entries in the map at
> > > the top of the page.
> > > 
> > > In TreeMap, size/size() is not a Bean Property (no?) so I tried
> > > in-line subclassing to expose the property:
> > > 
> > > <%
> > >   TreeMap treeMap = new TreeMap() {
> > >       public int getSize(){return size();}
> > >     };
> > >   pageContext.setAttribute("TableRows",treeMap);
> > > %>
> > > 
> > > now much later I try:
> > > 
> > > <TD>
> > > Search Results:&nbsp;<c:out value="${TableRows.size}"/>&nbsp;found.
> > > </TD>
> > > 
> > > I could just count things as they are added to the map
> > > over a series of SQL queries, but it seemed to me this
> > > was the better solution.. only the EL expression is null.
> > > 
> > > I'm sure I'm doing something wrong....
> > > 
> > > Thanks
> > > 
> > > Roy

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

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


Re: EL access to a bean property... ?

Posted by Bill Siggelkow <bi...@bellsouth.net>.
Roy, if you are using JSP 2.0 (e.g. with Tomcat 5) and JSTL 1.1 you can 
do the following:

<%@page isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

Map size is ${fn:length(TableRows)}


Roy Benjamin wrote:

> Very interesting, so wrapping would work, but you can't
> just expose a Bean property.
> 
> I've switched to c-rt for now, 
> 
> Thanks!
> 
> On Fri, 2004-03-26 at 10:35, Kris Schneider wrote:
> 
>>Maps are treated differently than regular JavaBeans so that you can't access
>>bean properties. For example, every object has a bean property called "class",
>>but you won't get any output if you try ${map.class}. It's even more fun to try
>>and get at a map's "empty" property ;-). If all you're concerned with is
>>testing whether a map is empty or not, you can use ${not empty map}. If you
>>really need the size of the map, you could try the Unstandard taglib:
>>
>>http://jakarta.apache.org/taglibs/sandbox/doc/unstandard-doc/intro.html
>>
>>Or do something like create a wrapper bean for collections that exposes a "size"
>>property and delegates to the wrapped collection.
>>
>>Quoting Roy Benjamin <Be...@adobe.com>:
>>
>>
>>>I am displaying the values in a TreeMap using forEach tag.
>>>However, I only want to do this if the map is not empty.
>>>I also need to display the count of entries in the map at
>>>the top of the page.
>>>
>>>In TreeMap, size/size() is not a Bean Property (no?) so I tried
>>>in-line subclassing to expose the property:
>>>
>>><%
>>>  TreeMap treeMap = new TreeMap() {
>>>      public int getSize(){return size();}
>>>    };
>>>  pageContext.setAttribute("TableRows",treeMap);
>>>%>
>>>
>>>now much later I try:
>>>
>>><TD>
>>>Search Results:&nbsp;<c:out value="${TableRows.size}"/>&nbsp;found.
>>></TD>
>>>
>>>I could just count things as they are added to the map
>>>over a series of SQL queries, but it seemed to me this
>>>was the better solution.. only the EL expression is null.
>>>
>>>I'm sure I'm doing something wrong....
>>>
>>>Thanks
>>>
>>>Roy


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


Re: EL access to a bean property... ?

Posted by Roy Benjamin <Be...@adobe.com>.
Very interesting, so wrapping would work, but you can't
just expose a Bean property.

I've switched to c-rt for now, 

Thanks!

On Fri, 2004-03-26 at 10:35, Kris Schneider wrote:
> Maps are treated differently than regular JavaBeans so that you can't access
> bean properties. For example, every object has a bean property called "class",
> but you won't get any output if you try ${map.class}. It's even more fun to try
> and get at a map's "empty" property ;-). If all you're concerned with is
> testing whether a map is empty or not, you can use ${not empty map}. If you
> really need the size of the map, you could try the Unstandard taglib:
> 
> http://jakarta.apache.org/taglibs/sandbox/doc/unstandard-doc/intro.html
> 
> Or do something like create a wrapper bean for collections that exposes a "size"
> property and delegates to the wrapped collection.
> 
> Quoting Roy Benjamin <Be...@adobe.com>:
> 
> > I am displaying the values in a TreeMap using forEach tag.
> > However, I only want to do this if the map is not empty.
> > I also need to display the count of entries in the map at
> > the top of the page.
> > 
> > In TreeMap, size/size() is not a Bean Property (no?) so I tried
> > in-line subclassing to expose the property:
> > 
> > <%
> >   TreeMap treeMap = new TreeMap() {
> >       public int getSize(){return size();}
> >     };
> >   pageContext.setAttribute("TableRows",treeMap);
> > %>
> > 
> > now much later I try:
> > 
> > <TD>
> > Search Results:&nbsp;<c:out value="${TableRows.size}"/>&nbsp;found.
> > </TD>
> > 
> > I could just count things as they are added to the map
> > over a series of SQL queries, but it seemed to me this
> > was the better solution.. only the EL expression is null.
> > 
> > I'm sure I'm doing something wrong....
> > 
> > Thanks
> > 
> > Roy


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


Re: EL access to a bean property... ?

Posted by Kris Schneider <kr...@dotech.com>.
Maps are treated differently than regular JavaBeans so that you can't access
bean properties. For example, every object has a bean property called "class",
but you won't get any output if you try ${map.class}. It's even more fun to try
and get at a map's "empty" property ;-). If all you're concerned with is
testing whether a map is empty or not, you can use ${not empty map}. If you
really need the size of the map, you could try the Unstandard taglib:

http://jakarta.apache.org/taglibs/sandbox/doc/unstandard-doc/intro.html

Or do something like create a wrapper bean for collections that exposes a "size"
property and delegates to the wrapped collection.

Quoting Roy Benjamin <Be...@adobe.com>:

> I am displaying the values in a TreeMap using forEach tag.
> However, I only want to do this if the map is not empty.
> I also need to display the count of entries in the map at
> the top of the page.
> 
> In TreeMap, size/size() is not a Bean Property (no?) so I tried
> in-line subclassing to expose the property:
> 
> <%
>   TreeMap treeMap = new TreeMap() {
>       public int getSize(){return size();}
>     };
>   pageContext.setAttribute("TableRows",treeMap);
> %>
> 
> now much later I try:
> 
> <TD>
> Search Results:&nbsp;<c:out value="${TableRows.size}"/>&nbsp;found.
> </TD>
> 
> I could just count things as they are added to the map
> over a series of SQL queries, but it seemed to me this
> was the better solution.. only the EL expression is null.
> 
> I'm sure I'm doing something wrong....
> 
> Thanks
> 
> Roy

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

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