You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Henry Lu <zh...@umich.edu> on 2002/02/12 20:58:58 UTC

iterate tag usage

I have a jsp page with the following code:

<logic:iterate id="regList" name="RegForm" property="listArray">
<bean:write name="regList" property="listArray"/>
</logic:iterate>

and in the RegForm.java java bean, we have the following code:

   private String[] listArray;

   public String[] getListArray()
   {
      return listArray;
   }

But when I query the page, I got error:
javax.servlet.ServletException: No collection found

Why and how to fix?



---------------------------------------------------------------------------
Henry Lu
MCIT                                            phone: (734) 936-2063
University of Michigan Medical Center           fax:   (734) 763-4372


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: iterate tag usage

Posted by Moritz Petersen <de...@pnpconsult.com>.
Hehe, nope. ;-)

Look: the return value of the getXYZ() method must be a
java.util.Collection, Iterator etc. but _not_ an array. By the way: your
code would not even compile.

private Vector listVector;
// A Vector implements the Collection interface. That is good.

public Vector getListVector()
// This works. "Vector".

Have fun!

Moritz.

P.S.: What the hell is "VectorString"?

> Thanks for your info! Do you think the following will work?
>
> <logic:iterate id="regList" name="RegForm" property="listVector">
> <bean:write name="regList" property="listVector"/>
> </logic:iterate>
>
>    private Vector listVector;
>
>    public VectorString[] getListVector()
>    {
>       return listVector;
>    }
>
> Thank you again!


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: iterate tag usage

Posted by Henry Lu <zh...@umich.edu>.
Thanks for your info! Do you think the following will work?

<logic:iterate id="regList" name="RegForm" property="listVector">
<bean:write name="regList" property="listVector"/>
</logic:iterate>

   private Vector listVector;

   public VectorString[] getListVector()
   {
      return listVector;
   }

Thank you again!


---------------------------------------------------------------------------
Henry Lu
MCIT                                            phone: (734) 936-2063
University of Michigan Medical Center           fax:   (734) 763-4372

On Tue, 12 Feb 2002, Moritz Petersen wrote:

> Henry,
>
> an array does not extend java.util.Collection. The iterate tag expects a
> Collection (which contains a 'iterator()' method). So you have to convert
> the array into a collection, either by simply not using arrays in favor of
> collections, or by implementing an additional method like:
>
> public Collection getListCollection()
> {
>    return Arrays.asList(listArray);
> }
>
> BTW: I would avoid arrays.
>
> Cheers,
> Moritz.
>
> > I have a jsp page with the following code:
> >
> > <logic:iterate id="regList" name="RegForm" property="listArray">
> > <bean:write name="regList" property="listArray"/>
> > </logic:iterate>
> >
> > and in the RegForm.java java bean, we have the following code:
> >
> >    private String[] listArray;
> >
> >    public String[] getListArray()
> >    {
> >       return listArray;
> >    }
> >
> > But when I query the page, I got error:
> > javax.servlet.ServletException: No collection found
> >
> > Why and how to fix?
> >
> >
> >
> > ------------------------------------------------------------------
> > ---------
> > Henry Lu
> > MCIT                                            phone: (734) 936-2063
> > University of Michigan Medical Center           fax:   (734) 763-4372
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >
> >
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: iterate tag usage

Posted by Moritz Petersen <de...@pnpconsult.com>.
Henry,

an array does not extend java.util.Collection. The iterate tag expects a
Collection (which contains a 'iterator()' method). So you have to convert
the array into a collection, either by simply not using arrays in favor of
collections, or by implementing an additional method like:

public Collection getListCollection()
{
   return Arrays.asList(listArray);
}

BTW: I would avoid arrays.

Cheers,
Moritz.

> I have a jsp page with the following code:
>
> <logic:iterate id="regList" name="RegForm" property="listArray">
> <bean:write name="regList" property="listArray"/>
> </logic:iterate>
>
> and in the RegForm.java java bean, we have the following code:
>
>    private String[] listArray;
>
>    public String[] getListArray()
>    {
>       return listArray;
>    }
>
> But when I query the page, I got error:
> javax.servlet.ServletException: No collection found
>
> Why and how to fix?
>
>
>
> ------------------------------------------------------------------
> ---------
> Henry Lu
> MCIT                                            phone: (734) 936-2063
> University of Michigan Medical Center           fax:   (734) 763-4372
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>