You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Marc Lustig <ma...@marclustig.com> on 2002/09/30 09:12:53 UTC

How to pass object to Intake macro

Hi,

instead of typing

#if (!$kundeanlegenGroup.PasswordValue.isValid())
$kundeanlegenGroup.PasswordValue.Message<br>
#end
<input type="Text" name="$kundeanlegenGroup.PasswordValue.Key"
value="$!kundeanlegenGroup.PasswordValue" size="20">

in my template I'd like to pass $kundeanlegenGroup.PasswordValue to macro
that looks like that:

#macro (valTextFeld $bezeichnung $feld $size)
<tr><td align="right">$bezeichnung</td><td>
#if (!$feld.isValid())
$feld.Message<br>
#end
<input type="Text" name="$feld.Key" value="$!feld" size="$size"></td></tr>
#end

But calling #valTextFeld("Name:" $kundeanlegenGroup.PasswordValue 20)
doesn't work unfortunately.

Is it not possible to pass an object to an Intake macro?
If yes, how to do so?

TIA.
Marc


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


AW: How to pass object to Intake macro

Posted by Marc Lustig <ma...@marclustig.com>.
> I think you really mean "Is it not possible to pass an object to 
> a Velocity
> macro?"

yes, of course, sorry...
I have my macros in seperate file and added to TR.props. It works fine.
Anyway, I changed some other tings, and the macro works now!
I don't know what was the problem, but as it works now I don't care.
Thanks!

Marc

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


Re: AW: How to pass object to 'Velocity' macro

Posted by Konstantin Priblouda <kp...@yahoo.com>.
> Most likely it is explained there.  The '!' means
> 'don't print anything if
> the expression evaluates to null' - without the '!'
> the expression itself
> will be printed.

Well, currently it's not completely true. 
I works for simple reference, but not for methods / 
properties

$!order.receiverAddress prints out
iteself if getReceiverAddress() returns null...

I belive this could be a bug...

regards,

=====
Konstantin Priblouda ( ko5tik )    Freelance Software developer
< http://www.pribluda.de > < play java games -> http://www.yook.de >
< render charts online -> http://www.pribluda.de/povray/ >

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com

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


Re: AW: How to pass object to 'Velocity' macro

Posted by Scott Eade <se...@backstagetech.com.au>.
> From: "Marc Lustig" <ma...@marclustig.com>
> 
> #macro (valTextFeld $bezeichnung $feld $size)
> <tr><td align="right">$bezeichnung</td><td>
> <input type="Text" name="$feld.Key" value="$!feld" size="$size">
> #if (!$feld.isValid())
> <span style="color: red">$feld.Message</span>
> #end
> 
> After the form is processed with invalid fields, the error messages do
> appear, but not the values that have been typed into the input-field before.
> 
> after $feld=mygroup.myfield
> "$!feld" seems not to work.
Try $!field.Value
> 
> Is it necessary to use "$!mygroup.myfield" explicitly ?
> Or do you know a work around to use ?
> 
> (I'm not quite sure what this "$!xxx" syntax is all about. Maybe it is
> explained in Velocity how-to.)
Most likely it is explained there.  The '!' means 'don't print anything if
the expression evaluates to null' - without the '!' the expression itself
will be printed.

Scott
-- 
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au



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


AW: How to pass object to 'Velocity' macro

Posted by Marc Lustig <ma...@marclustig.com>.
However, Scott, there is one problem left:

#macro (valTextFeld $bezeichnung $feld $size)
<tr><td align="right">$bezeichnung</td><td>
<input type="Text" name="$feld.Key" value="$!feld" size="$size">
#if (!$feld.isValid())
<span style="color: red">$feld.Message</span>
#end


After the form is processed with invalid fields, the error messages do
appear, but not the values that have been typed into the input-field before.

after $feld=mygroup.myfield
"$!feld" seems not to work.

Is it necessary to use "$!mygroup.myfield" explicitly ?
Or do you know a work around to use ?

(I'm not quite sure what this "$!xxx" syntax is all about. Maybe it is
explained in Velocity how-to.)

Regards
Marc




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


Re: How to pass object to Intake macro

Posted by Scott Eade <se...@backstagetech.com.au>.
> From: "Marc Lustig" <ma...@marclustig.com>
> 
> Hi,
> 
> instead of typing
> 
> #if (!$kundeanlegenGroup.PasswordValue.isValid())
> $kundeanlegenGroup.PasswordValue.Message<br>
> #end
> <input type="Text" name="$kundeanlegenGroup.PasswordValue.Key"
> value="$!kundeanlegenGroup.PasswordValue" size="20">
> 
> in my template I'd like to pass $kundeanlegenGroup.PasswordValue to macro
> that looks like that:
> 
> #macro (valTextFeld $bezeichnung $feld $size)
> <tr><td align="right">$bezeichnung</td><td>
> #if (!$feld.isValid())
> $feld.Message<br>
> #end
> <input type="Text" name="$feld.Key" value="$!feld" size="$size"></td></tr>
> #end
> 
> But calling #valTextFeld("Name:" $kundeanlegenGroup.PasswordValue 20)
> doesn't work unfortunately.
> 
> Is it not possible to pass an object to an Intake macro?
I think you really mean "Is it not possible to pass an object to a Velocity
macro?"
> If yes, how to do so?
Yes, you can pass objects to velocity macros - I highly recommend them (my
GlobalMacros.vm file is currently 1237 lines long!)

Your macro and the call look okay to me.  Are you getting an error message
of some kind?  Remember that if you are using GlobalMacros.vm the macros
here are only parsed when the servlet container loads unless you explicitly
parse the file using:

#parse("GlobalMacros.vm")

And even then there is the possibility (depending on where you put the
statement) that you might need to hit the above line of code a second time
before changes to the macro are apparent.  If I am doing extensive macro
development I include the above parse statement in either the specific page
template I am working on or in my default layout if I am changing lots of
pages - but I only ever do this in development.

There are a few relevant properties in TR.props and velocity.log is a good
place to check for problems.

Cheers,

Scott
-- 
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au



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