velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Barbara Baughman <baugh...@utdallas.edu>
Subject Re: Defining iterator for #foreach
Date Mon, 18 Oct 2004 18:45:32 GMT
Well, I think I answered my own question.  It's NO.

Barbara Baughman
X2157

On Mon, 18 Oct 2004, Barbara Baughman wrote:

> Actually, I was trying to create a class that was immutable, which
> means I wouldn't want to implement Collection.  If I have the class
> just implement Iterator would that do it?
>
> Barbara Baughman
> X2157
>
> On Mon, 18 Oct 2004, Simon Christian wrote:
>
> > Hi Barbara,
> >
> > I believe that either your class will need to implement the Collection
> > interface, or you'd need to call the iterator() method explicitly i.e.
> >
> > 	#foreach( $element in $myObj.iterator() )
> >
> > Of course Velocity will complain/warn you about the fact that the
> > iterator is not reusable. However it sounds like you've all but
> > implemented the Collection anyway - providing you're able to extend
> > java.util.AbstractCollection (leaving only size() and iterator() to
> > implement).
> >
> > - simon
> >
> >
> > Barbara Baughman wrote:
> > > It looks like, for the first time, I am passing an object to a foreach
> > > loop that that is not a Vector, HashMap, or Array.
> > >
> > > I instead have a class that essentially wraps a Vector of a certain
> > > type.  It includes a method:
> > >
> > > public Iterator iterator() {
> > >    return v.iterator(); // return iterator of the underlying Vector
> > > }
> > >
> > > I thought all classes with iterators would work with a #foreach loop
> > > (even though I don't see that in the documentation.  However, I get
> > > the error message:
> > >
> > > Mon Oct 18 11:22:49 CDT 2004   [warn] Could not determine type of
> > > iterator in #foreach loop  at [0,0] in template member/info/facstaff.vm
> > >
> > > The template output only provides one blank line, even though the
> > > size() method indicates there are 84 members.
> > >
> > > Any hints or tips?
> > >
> > > Barbara Baughman
> > > X2157
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

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


Mime
View raw message