velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Withers John Z" <John.With...@irs.gov>
Subject RE: How can I get the length of Array ?
Date Thu, 25 May 2006 14:42:56 GMT
I stand corrected.  I've never actually tried what Nathan describes,
mostly because I didn't think it would work.  In the same case, I would
have created an ArrayList (or something similar) and put it in the
context instead.

Thanks for setting the record straight, Nathan. 


John Withers 

-----Original Message-----
From: Nathan Bubna [mailto:nbubna@gmail.com] 
Sent: Thursday, May 25, 2006 9:20 AM
To: Velocity Users List
Subject: Re: How can I get the length of Array ?

That's because Velocity creates an ArrayList when you do that.

However, when you do context.put("array", new int[] { 1, 2 ,3 }), then
it is a different story.

i believe our plan after 1.5 is to have Velocity transparently treat
$array as a List, but at this point, it does not do that.

On 5/25/06, Withers John Z <John.Withers@irs.gov> wrote:
> I beg to differ.  The following code works for me in a production
> template:
>
> #set ($chosen = [])
> #foreach ($item in $list)
>   #if ($item.isChosen())
>     #set ($n = $chosen.add($item))
>   #end
> #end
> $chosen.size() ## Displays the number of items in the $chosen array
>
> John
>
> John Withers
>
> -----Original Message-----
> From: Will Glass-Husain [mailto:wglass@forio.com]
> Sent: Thursday, May 25, 2006 8:50 AM
> To: Velocity Users List
> Subject: Re: How can I get the length of Array ?
>
> Not true, though it's on our feature request list.
>
> Use ListTool from the Velocity tools project.
>
> WILL
>
> Withers John Z wrote:
> > I think $arr.size() would return the length of the array.  If memory

> > serves, Velocity implements arrays as ArrayList.
> >
> > John Withers
> >
> > -----Original Message-----
> > From: trad-ex [mailto:trad-ex@inter7.jp]
> > Sent: Thursday, May 25, 2006 1:13 AM
> > To: Velocity Users List
> > Subject: How can I get the length of Array ?
> >
> > Hi all,
> >
> > In the Velocity realm, how can I get the length of Array ?
> > For instance,
> >
> > #set( $arr = __set int[] value__ )
> > #if( $arr.length > 0 )
> >  ...(snip)...
> >
> > $arr.length is always null. Why ?
> > I always use helper Object to avoid this issue.
> > For example,
> >
> > $helperObj.lengthOf( $arr )
> >
> > This method, lengthOf, is described below:
> >
> >  public int lengthOf( Object[] objects )  {
> >    if( objects == null)
> >      return 0;
> >    return objects.length;
> >  }
> >
> > Best Regards,
> > trad-ex
> >
> >
> > --------------------------------------------------------------------
> > - 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
> >
> >
> >
>
> --
> Forio Business Simulations
>
> Will Glass-Husain
> phone (415) 440-7500 x89
> mobile (415) 235-4293
> wglass@forio.com
> www.forio.com
>
>
> ---------------------------------------------------------------------
> 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