velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <>
Subject Re: String array
Date Wed, 07 Mar 2001 14:15:52 GMT
Andreas Wikberger wrote:
> Hello,
> I have a problem with passing a String array as a parameter to a
> predefined java method from my velocity template.
> I have a java class in my Context called $util. In this class I have a
> method as follows:
> public void getList(int noOfRows, String [] attrs){
>   ...
> }
> >From my velocity template I call this method like this:
> ...
> #set( $rows = 5)
> #set( $attrs = ["name","phone"])
> $util.getList($rows, $attrs)
> ...

$attrs is an ArrayList, not a String[].

The array and range operators :

["a","b"]  or [1..10]

both return a java.util.ArrayList

> The output of the lines above becomes $util.getList($rows, $attrs) in
> plain text. And in my velocity.log file I get a warning about a
> ReferenceException ( $util.getList($row, $attrs) is not a valid
> reference.)

Because it can't find a method with the right signature.
> If I rewove the array as a parameter and only have an integer as
> parameter the method is called and produces the output it is supposed to
> do. Does not  #set( $attrs = ["name","phone"]) a string array equivalent
> to a java String[].

Just change your method, or add one as a wrapper that takes an array
list and calls the orignal one, and all should be fine.


Geir Magnusson Jr.                     
Developing for the web?  See

View raw message