You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Christofer 'boz' Jennings <bo...@cox.net> on 2005/03/18 16:06:50 UTC

reading an array's length?

I want to get an array's length wit VTL, but $mayArray.length doesn't 
work. How s it done?

Thanks!
,boz


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


Re: reading an array's length?

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Jian,

> I also used Array Tool before. However, looking at the source of it,
> it appears to me that every time you call a method of the Array tool,
> it creates a new instance of the array list internally, which is mild
> performance problem.

The current version uses reflection, so shouldn't be so much of an overhead.  :)

Best regards,
-- Shinobu

--
Shinobu Kawai <sh...@gmail.com>

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


Re: reading an array's length?

Posted by jian chen <ch...@gmail.com>.
Hi,

I also used Array Tool before. However, looking at the source of it,
it appears to me that every time you call a method of the Array tool,
it creates a new instance of the array list internally, which is mild
performance problem.

So, now I tried to avoid using it. What I did is to use standard java
Arrays conversion to convert array to a list and then pass it to into
the template.

Just my 2 cents. 

Cheers,

Jian

On Fri, 18 Mar 2005 11:07:30 -0500, Mike Kienenberger
<mk...@alaska.net> wrote:
> Christofer 'boz' Jennings <bo...@cox.net> wrote:
> > Is there a binary for ArrayTool somewhere or do I just build it?
> >
> > And how would it get configured programmatically (eg.
> > velocity.setProperty())?
> 
> It's included with the latest (cvs) Velocity tools, I think.
> 
> It's also available on the Velocity Wiki.
> 
> http://wiki.apache.org/jakarta-velocity/ArrayTool
> 
> It's easy enough to just add it to your project as another java file (that's
> what I'd do).
> 
> To use it, either configure it via toolbox.xml (if you're using that) or
> just do a velocityContext.put("arrayTool", new ArrayTool());
> 
> ---------------------------------------------------------------------
> 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


Re: reading an array's length?

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Mike,

> > Is there a binary for ArrayTool somewhere or do I just build it?

> It's included with the latest (cvs) Velocity tools, I think.

Not yet.  I'm going to get the List support back first.
## svn, BTW  ;)

Best regards,
-- Shinobu

--
Shinobu Kawai <sh...@gmail.com>

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


Re: reading an array's length?

Posted by Christofer Boz Jennings <bo...@cox.net>.
And its nice to use something that makes me say "ahh" instead of 
"argh!" .... :-)
,boz

On Mar 18, 2005, at 6:09 PM, Mike Kienenberger wrote:

> Christofer 'boz' Jennings <bo...@cox.net> wrote:
>> Ahh. Now I get tools.... So simple :-)
>
> Yeah, that's exactly how I felt.  It just took me a lot longer to 
> figure it
> out.
>
> Wonderfully brilliant yet simple idea once you realize that there's 
> nothing
> special about a tool.   :)
>
> ---------------------------------------------------------------------
> 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


Re: reading an array's length?

Posted by Mike Kienenberger <mk...@alaska.net>.
Christofer 'boz' Jennings <bo...@cox.net> wrote:
> Ahh. Now I get tools.... So simple :-)

Yeah, that's exactly how I felt.  It just took me a lot longer to figure it 
out.

Wonderfully brilliant yet simple idea once you realize that there's nothing 
special about a tool.   :)

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


Re: reading an array's length?

Posted by Christofer 'boz' Jennings <bo...@cox.net>.
Ahh. Now I get tools.... So simple :-)

Dummied the ArrayTool down to just what I need. Later it can be swapped 
for the real thing I guess. Herre's what I did....

//----------------------------- start snip
package mystuff;

import java.lang.reflect.Array;

public class VelocityArrayTool
{

     /**
      * Default constructor.
      */
     public VelocityArrayTool()
     {
     }

     public Integer length(Object array)
     {
     		int length;
     		try {
     			length = Array.getLength(array);
     		}
     		catch (Exception e) {
     			return null;
     		}

         return new Integer(length);
     }

}
//----------------------------- end snip

then added it to the context as you suggested.

Thanks for all the help!

,boz

On Mar 18, 2005, at 8:07 AM, Mike Kienenberger wrote:

> Christofer 'boz' Jennings <bo...@cox.net> wrote:
>> Is there a binary for ArrayTool somewhere or do I just build it?
>>
>> And how would it get configured programmatically (eg.
>> velocity.setProperty())?
>
> It's included with the latest (cvs) Velocity tools, I think.
>
> It's also available on the Velocity Wiki.
>
> http://wiki.apache.org/jakarta-velocity/ArrayTool
>
> It's easy enough to just add it to your project as another java file 
> (that's
> what I'd do).
>
> To use it, either configure it via toolbox.xml (if you're using that) 
> or
> just do a velocityContext.put("arrayTool", new ArrayTool());
>
> ---------------------------------------------------------------------
> 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


Re: reading an array's length?

Posted by Mike Kienenberger <mk...@alaska.net>.
Christofer 'boz' Jennings <bo...@cox.net> wrote:
> Is there a binary for ArrayTool somewhere or do I just build it?
> 
> And how would it get configured programmatically (eg. 
> velocity.setProperty())?

It's included with the latest (cvs) Velocity tools, I think.

It's also available on the Velocity Wiki.

http://wiki.apache.org/jakarta-velocity/ArrayTool

It's easy enough to just add it to your project as another java file (that's 
what I'd do).

To use it, either configure it via toolbox.xml (if you're using that) or 
just do a velocityContext.put("arrayTool", new ArrayTool());

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


Re: reading an array's length?

Posted by Christofer 'boz' Jennings <bo...@cox.net>.
Thanks Steve!

Is there a binary for ArrayTool somewhere or do I just build it?

And how would it get configured programmatically (eg. 
velocity.setProperty())?

???
,boz


On Mar 18, 2005, at 7:41 AM, Steve O'Hara wrote:

>
> Velocity isn't too great at referencing arrays but there is a tool to 
> help
> here;
>
> http://wiki.apache.org/jakarta-velocity/ArrayTool
>
> Steve
>
> -----Original Message-----
> From: Christofer 'boz' Jennings [mailto:boz@cox.net]
> Sent: 18 March 2005 15:07
> To: velocity-user@jakarta.apache.org
> Subject: reading an array's length?
>
>
> I want to get an array's length wit VTL, but $mayArray.length doesn't
> work. How s it done?
>
> Thanks!
> ,boz
>
>
> ---------------------------------------------------------------------
> 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


RE: reading an array's length?

Posted by Steve O'Hara <so...@pivotal-solutions.co.uk>.
Velocity isn't too great at referencing arrays but there is a tool to help
here;

http://wiki.apache.org/jakarta-velocity/ArrayTool

Steve

-----Original Message-----
From: Christofer 'boz' Jennings [mailto:boz@cox.net]
Sent: 18 March 2005 15:07
To: velocity-user@jakarta.apache.org
Subject: reading an array's length?


I want to get an array's length wit VTL, but $mayArray.length doesn't
work. How s it done?

Thanks!
,boz


---------------------------------------------------------------------
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