You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Foth, Oliver" <Ol...@gedas.de> on 2002/10/14 09:36:14 UTC
variable display problem
Hi everybody,
I have the following problem, or better: challenge ;-)
In a java file I've created some variables within an for loop:
for (i = 0, i < something.length(), i++)
{
...
context.put("aufdat_"+i, aufdat);
...
}
I can use them in the vm file and they are displayed correctly. But instead
of using them like:
$aufdat_1<BR/>
$aufdat_2<BR/>
...
I need to use them in another loop:
#set ($index = 0)
#foreach ($thing in $something)
#set ($index = $index + 1)
$aufdat_$index
#end
How can I have "$aufdat_$index" displayed correctly?
Gruß,
Oliver Foth
> ----------------------------------------------------
> gedas deutschland GmbH
> Teilelogistik
> Johann-Siegmund-Schuckert-Str. 2a
> D-34225 Baunatal
> Telefon/phone +49-561-49995-34
> Telefax/telefax +49-561-49995-52
> Mailto: Oliver.Foth@gedas.de
> http://www.gedas.com <http://www.gedas.com>
> ----------------------------------------------------
>
>
Re: variable display problem
Posted by Jonathan Revusky <re...@wanadoo.es>.
On Monday 14 October 2002 09:36 am, Foth, Oliver wrote:
> Hi everybody,
>
> I have the following problem, or better: challenge ;-)
> In a java file I've created some variables within an for loop:
>
> for (i = 0, i < something.length(), i++)
> {
> ...
> context.put("aufdat_"+i, aufdat);
> ...
> }
It seems to me that you should just put the variables in an ArrayList.
ArrayList aufdatei = new ArrayList();
for (i = 0; i<something.length(); i++)
{
aufdatei.add(aufdat)
...
}
and then in the VM file, use:
$aufdatei.get($index)
etcetera.
(Pity you can't just write ${aufdatei[index]} like in FreeMarker. ;-))
Hope that helps,
Jonathan Revusky
--
FreeMarker-Velocity comparison doc
http://freemarker.sourceforge.net/fmVsVel.html
Velocity->FreeMarker template conversion utility
http://freemarker.sourceforge.net/usCavalry.html
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: variable display problem
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
You can just use an ArrayList :
List list = new ArrayList();
for(i=0; i < something.length(); i++)
{
....
list.add(aufdat);
}
context.put("aufdatList", list);
And then in your template :
#foreach($aufdat in $aufdatList)
$aufdat<br>
#end
Or
$aufdatList.get(3)
for direct access
On 10/14/02 3:36 AM, "Foth, Oliver" <Ol...@gedas.de> wrote:
> Hi everybody,
>
> I have the following problem, or better: challenge ;-)
> In a java file I've created some variables within an for loop:
>
> for (i = 0, i < something.length(), i++)
> {
> ...
> context.put("aufdat_"+i, aufdat);
> ...
> }
>
> I can use them in the vm file and they are displayed correctly. But instead
> of using them like:
>
> $aufdat_1<BR/>
> $aufdat_2<BR/>
> ...
>
> I need to use them in another loop:
>
> #set ($index = 0)
> #foreach ($thing in $something)
> #set ($index = $index + 1)
> $aufdat_$index
> #end
>
> How can I have "$aufdat_$index" displayed correctly?
>
>
> Gruß,
>
> Oliver Foth
>> ----------------------------------------------------
>> gedas deutschland GmbH
>> Teilelogistik
>> Johann-Siegmund-Schuckert-Str. 2a
>> D-34225 Baunatal
>> Telefon/phone +49-561-49995-34
>> Telefax/telefax +49-561-49995-52
>> Mailto: Oliver.Foth@gedas.de
>> http://www.gedas.com <http://www.gedas.com>
>> ----------------------------------------------------
>>
>>
>
--
Geir Magnusson Jr.
geirm@adeptra.com +1-203-355-2219 (w)
Adeptra Inc. +1-203-247-1713 (m)
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: variable display problem
Posted by Peter Romianowski <me...@gmx.de>.
Perhaps you might want to put the Objects as a Map into the context.
Map map = new HashMap();
for (i = 0, i < something.length(), i++)
{
...
map.put (""+i, aufdat);
...
}
context.put("aufdat", map);
And in the VM:
#foreach ($thing in $something)
#set ($index = $index + 1)
$aufdat.get($i)
#end
As I see, you can use a List, too, of course... depends on what your are
doing further :)
Peter
> -----Original Message-----
> From: Foth, Oliver [mailto:Oliver.Foth@gedas.de]
> Sent: Monday, October 14, 2002 9:36 AM
> To: 'velocity-user@jakarta.apache.org'
> Subject: variable display problem
>
>
> Hi everybody,
>
> I have the following problem, or better: challenge ;-)
> In a java file I've created some variables within an for loop:
>
> for (i = 0, i < something.length(), i++)
> {
> ...
> context.put("aufdat_"+i, aufdat);
> ...
> }
>
> I can use them in the vm file and they are displayed
> correctly. But instead of using them like:
>
> $aufdat_1<BR/>
> $aufdat_2<BR/>
> ...
>
> I need to use them in another loop:
>
> #set ($index = 0)
> #foreach ($thing in $something)
> #set ($index = $index + 1)
> $aufdat_$index
> #end
>
> How can I have "$aufdat_$index" displayed correctly?
>
>
> Gruß,
>
> Oliver Foth
> > ----------------------------------------------------
> > gedas deutschland GmbH
> > Teilelogistik
> > Johann-Siegmund-Schuckert-Str. 2a
> > D-34225 Baunatal
> > Telefon/phone +49-561-49995-34
> > Telefax/telefax +49-561-49995-52
> > Mailto: Oliver.Foth@gedas.de
> > http://www.gedas.com <http://www.gedas.com>
> > ----------------------------------------------------
> >
> >
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>