You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Chris Joelly <ch...@unycom.com> on 2004/01/13 18:34:21 UTC
interpolation of variables ...
Hello!
i'm new to velocity and run into the following problem:
i set some data into the context from within my action class:
context.put("field-23", "data23");
context.put("field-24", "data24");
....
then in the velocity template i wanna do something like:
#foreach ( $df in $datafields )
#set ( $fieldname = "field-$df.getFieldId()" )
#set ( $fieldvalue = "${$fieldname}" )
<input type="text" name="$feldname" value="$fieldvalue"/>
#foreach
i wanna set a variable name dynamically and then lookup the context for
the value of this variable...
is this possible with velocity? if so, can anybody tell me how to do?
thx, Chris
--
mit freundlichen Grüßen / with kind regards
Ing. Christian Jölly @ Solutions
unycom Information Technology Services GmbH
A-8042 Graz | Schmiedlstraße 1 / III
Tel: ++43 (0)316 / 818 828 - 30
Fax: ++43 (0)316 / 818 828 - 38
chris.joelly@unycom.com
http://www.unycom.com
Polizist: "In ihrem Zustand heißt die Devise: Hände weg vom Steuer!"
Betrunkner Autofahrer: "Was, wenn ich blau bin soll ich auch noch
freihändig fahren?"
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: interpolation of variables ...
Posted by Claude Brisson <cl...@savoirweb.com>.
you must use an evaluator tool - there are two versions of those evaluators
provided in the tools subproject
CASE 1 : if you're not using VelocityViewServlet
context.put("ctx", context);
context.put("render", new org.apache.velocity.tools.generic.RenderTool());
then in the template :
#set ( $fieldname = "field-$df.getFieldId()" )
#set ( $fieldvalue = $render.eval($ctx,"$fieldname"))
-------------
CASE 2 : if you're using VelocityViewServlet
add the following entry to your toolbox.xml file :
<tool>
<key>render</key>
<scope>request</scope>
<class>org.apache.velocity.tools.view.tools.ViewRenderTool</class>
</tool>
then in the template :
#set ( $fieldvalue = $render.eval("$fieldname"))
--------------
Please note than case 1 will always work - case 2 is just the standard way
of using a tool with the VelocityViewServlet.
CloD
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org