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 "Dean A. Hoover" <dh...@rochester.rr.com> on 2004/05/10 19:04:11 UTC
getting a collection
I apologize if this is the wrong place to ask, but I am
having trouble solving this problem. I have written
a custom JSP tag for use in a struts 1.1 application
I am implementing. I have a domain object called
Series which has a method getCategoryIds that
returns a HashSet of Integers. A Series object
"series" is in the session when the following
JSP get invoked (its actually a struts-tile, probably
to complicate things further):
<%@ page isELIgnored="false" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-tiles" prefix="tiles" %>
<%@ taglib uri="/tags/els" prefix="els" %>
<!-- begin SeriesProps -->
<html:xhtml/>
<tr>
<td valign="top"><tiles:get name="titleLabel"/></td>
<td align="left"><html:text size="30" property="title"/></td>
</tr>
<td valign="top"><tiles:get name="descriptionLabel"/></td>
<td align="left">
<html:textarea cols="30" rows="3" property="description"/>
</td>
<tr>
<td valign="top"><tiles:get name="categoriesLabel"/></td>
<td align="left">
<els:categories property="categoryId" labelClass="text"
var="${series.categoryIds}"/>
</td>
</tr>
...
Anyway, I have been looking at other custom tags trying to figure out how
to get the collection into the custom tag I've written. It appears that
a class
called ExpressionEvaluatorManager would be used to get the collection
from the expression: ${series.categoryIds}, yet it goes too far and converts
the collection to a String like: "[1, 2, 7]". In the TLD for the tag I
write:
<tag>
<name>categories</name>
<tagclass>fi.els.tags.CategoriesTag</tagclass>
<attribute>
<name>property</name>
<required>true</required>
</attribute>
<attribute>
<name>labelClass</name>
<required>true</required>
</attribute>
<attribute>
<name>var</name>
<type>java.lang.Object</type>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
I attempt to get the collection back into the
tag as follows:
public class CategoriesTag extends TagSupport
{ public CategoriesTag()
{
super();
init();
}
public int doStartTag() throws JspException
{
if (this.var != null)
{
Object collection = ExpressionEvaluatorManager.evaluate("var",
this.var, Object.class, this, pageContext);
if (collection != null)
{
if (collection instanceof java.lang.String[])
log.debug("AAA: String[]");
else if (collection instanceof java.lang.String)
log.debug("AAA: String");
else
log.debug("AAA: Other");
}
}
...
public void setVar
(
String var
)
{
log.debug("AAA: setting var = '" + var + "'");
this.var = var;
}
private void init()
{
categoryIds = new HashSet();
var = null;
}
...
}
Like I said earlier, the HashSet collection is getting transformed
into a String. Can anyone tell me what I am doing wrong?
Thanks.
Dean
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
Re: getting a collection
Posted by "Dean A. Hoover" <dh...@rochester.rr.com>.
Thanks! Its easier than I thought. I came up with what I did
based on inspection of c:forEach tag source code.
Thanks.
Dean
Francois Beausoleil wrote:
>Hello Dean !
>
>On Mon, 10 May 2004 13:04:11 -0400, "Dean A. Hoover"
><dh...@rochester.rr.com> said:
>[snip]
>
>
>> public void setVar
>> (
>> String var
>> )
>> {
>> log.debug("AAA: setting var = '" + var + "'");
>> this.var = var;
>> }
>>
>>
>[snip]
>
>Lookee here... How is Java or EL expected to cast a HashSet to a String
>object ;) Declare setVar to expect a Set instance, and you'll be in
>business.
>
>Hope that helps !
>François
>Developer of Java Gui Builder
>http://jgb.sourceforge.net/
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
Re: getting a collection
Posted by Francois Beausoleil <fb...@users.sourceforge.net>.
Hello Dean !
On Mon, 10 May 2004 13:04:11 -0400, "Dean A. Hoover"
<dh...@rochester.rr.com> said:
[snip]
> public void setVar
> (
> String var
> )
> {
> log.debug("AAA: setting var = '" + var + "'");
> this.var = var;
> }
[snip]
Lookee here... How is Java or EL expected to cast a HashSet to a String
object ;) Declare setVar to expect a Set instance, and you'll be in
business.
Hope that helps !
François
Developer of Java Gui Builder
http://jgb.sourceforge.net/
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org