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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to