You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Alexander Mueller <al...@gmx.at> on 2002/03/06 23:50:13 UTC

foreach

Hi,

I am quite probably doing something wrong, however I am really lost :).

I have written a Context descendant, in order to stay independent from
the particular template (want to have the possibility to use the
variables in each HTML template). This context checks in the get
method the given key and returns the particular data. Now I have
a foreach statement in the template, which makes my Context returning
a string array. However it simply does not work. What am I doing wrong?


This is the get method of my own Context.

  public Object get(String key)
  {
    if (key.equals("dummy")) return new String[]{"1","2","3"};
    .
    .
  }


And this is the statement in the HTML template.

<select name="dummy">
 #foreach ($a in $dummy)
  <option>$a</option>
 #end
</select>


Thank you,
Alexander



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


Re: foreach

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 3/6/02 5:50 PM, "Alexander Mueller" <al...@gmx.at> wrote:

> 
> Hi,
> 
> I am quite probably doing something wrong, however I am really lost :).
> 
> I have written a Context descendant,

?  Something derived from the Context class?

>in order to stay independent from
> the particular template (want to have the possibility to use the
> variables in each HTML template). This context checks in the get
> method the given key and returns the particular data. Now I have
> a foreach statement in the template, which makes my Context returning
> a string array. However it simply does not work. What am I doing wrong?
> 
> 
> This is the get method of my own Context.
> 
> public Object get(String key)
> {
>   if (key.equals("dummy")) return new String[]{"1","2","3"};
>   .
>   .
> }
> 
> 
> And this is the statement in the HTML template.
> 
> <select name="dummy">
> #foreach ($a in $dummy)
> <option>$a</option>
> #end
> </select>

That's surprising, actually.  We use isArray() to check in the case of an
Object...

Anything in the log?


-- 
Geir Magnusson Jr.                                      geirm@optonline.net
System and Software Consulting
"Whoever would overthrow the liberty of a nation must begin by subduing the
freeness of speech." - Benjamin Franklin



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