Hi Gerry,
I spent quite a while trying to figure out how to dereference velocity
variables. The way I found was as follows:
1. In the class behind your velocity screen (ie: Index.java for Index.vm),
in the doBuildTemplate method, put the line context.put("ctx", context);
(this will add a reference to the context in your context)
2. In your velocity form, you can now get the value of a variable in the
context like this: $ctx.get("VALUE_$fieldname"). I haven't tried it in a
macro before, so you may need to pass ctx into your macro (it probably
depends on how your velocity is set up).
A 'weird' workaround for sure, but it should work for you.
David
-----Original Message-----
From: Gerry Duprey [mailto:[EMAIL PROTECTED]
Sent: Monday, February 16, 2004 1:10 PM
To: [EMAIL PROTECTED]
Subject: Velocity and evaluated symbol substitution
Howdy All,
I realize this is more a velocity question, but the velocity email list is
shared with the jakarta commons list and doesn't seem to have much velocity
traffic on it.
What I'm trying to do is create a velocity macro that can define an input
field using a fixed name for the field and have that macro have provisions
for
default values for the field based on the fields fixed name. For example,
I'd
love to do something like
#macro ( myInput $fieldName )
<INPUT TYPE="TEXT" NAME="FLD_$fieldName" VALUE="$!{VALUE_${fieldName}}">
#end
so
#myInput ( "UserName" )
becomes
<INPUT TYPE="TEXT" NAME="FLD_UserName" VALUE="Gerry">
Assuming my Context has a symbol called VALUE_UserName in it set to the
string
"Gerry" (i.e. context.put("VALUE_UserName", "Gerry")).
In short, the ability to have an interpreted reference/variable name.
It would also let me do things like having macros that knew how to display
errors attached to fields automatically. Consider:
#macro ( myInput $fieldName )
<INPUT TYPE="TEXT" NAME="FLD_$fieldName" VALUE="$!{VALUE_${fieldName}}">
#if ( ${ERROR_${fieldName}} )
<FONT COLOR="red">* ${ERROR_${fieldName}}</FONT>
#end
#end
This gives my verification routines a great deal of flexibility and allows
very generic forms processing modules.
Any thoughts (on how to do this or if you think I'm bonkers, that is :-)?
Gerry
--
Gerry Duprey
________________________________________
SchoolsOPEN, LLC
123 North Ashley, Suite 120
Ann Arbor, MI 48104
Phone (877) 483-1944 Ext. 401
Fax (734) 661-0819
Visit us Online at www.Schools-OPEN.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]