You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Colm McCartan <co...@owl.co.uk> on 2001/11/15 18:55:31 UTC

I give up!

Hello all,

OK, I'm certain this has been asked several times and that how to do is buried 
in the ref manual somewhere but I can't find this in the archive and its driving 
me mad trying to figure it out:

I'm trying to call an object method from within an if statement in a template 
like so, e.g.:

if ($user.hasDocPermission("Maintainer", "$document.id", $document.vnum))

but it fails to even hit the method (to my surprise, Velocity doesn't complain 
about type mismatching, invalid referencing or anything, just fails silently)

If I hard-wire it like so:

if ($user.hasDocPermission("Maintainer", "abc12de", 1))

it works a treat...

My tiny mind is failing to understand something to do with escaping the quotes 
here I think but I'd be grateful if anyone could point out what.. 

Could I perhaps use a directive to build the argument list first? I would then 
need to know how to escape a double quote in a set directive, yes? My various 
(horrific looking) attempts at this are throwing all sorts of parse 
exceptions...

Thanks a lot for any help...
colm



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


Re: I give up!

Posted by Christoph Reck <Ch...@dlr.de>.
Hi Colm,

is the property $document.vnum returning an int or Integer?

Since using the digit 1 works, $user.hasDocPermission seems to be
requiring an int or Integer as last parameter (the first two params 
seem strings). Note that velocity will not do typecasting (other than
Integer to int), so either $document.vnum must return int (or Integer)
or you will need a context tool that does the conversion.

The poor mans trick (no need to write a context tool) for converting 
a String to an int:
#set( $n = 0 )
if( $user.hasDocPermission("Maintainer", "$document.id", $n.parseInt($document.vnum) )


:) Christoph


Colm McCartan wrote:
> 
> Hello all,
> 
> OK, I'm certain this has been asked several times and that how to do is buried
> in the ref manual somewhere but I can't find this in the archive and its driving
> me mad trying to figure it out:
> 
> I'm trying to call an object method from within an if statement in a template
> like so, e.g.:
> 
> if ($user.hasDocPermission("Maintainer", "$document.id", $document.vnum))
> 
> but it fails to even hit the method (to my surprise, Velocity doesn't complain
> about type mismatching, invalid referencing or anything, just fails silently)
> 
> If I hard-wire it like so:
> 
> if ($user.hasDocPermission("Maintainer", "abc12de", 1))
> 
> it works a treat...
> 
> My tiny mind is failing to understand something to do with escaping the quotes
> here I think but I'd be grateful if anyone could point out what..
> 
> Could I perhaps use a directive to build the argument list first? I would then
> need to know how to escape a double quote in a set directive, yes? My various
> (horrific looking) attempts at this are throwing all sorts of parse
> exceptions...
> 
> Thanks a lot for any help...
> colm
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

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


Re: I give up!

Posted by "Henning P. Schmiedehausen" <ma...@hometree.net>.
Colm McCartan <co...@owl.co.uk> writes:

>I'm trying to call an object method from within an if statement in a template 
>like so, e.g.:

>if ($user.hasDocPermission("Maintainer", "$document.id", $document.vnum))

>if ($user.hasDocPermission("Maintainer", "abc12de", 1))

>it works a treat...

the Bean Method resolution works only if your methods really match

String get<name>(void)

So if getVnum() or getId() don't match that signature, you _must_ write

if ($user.hasDocPermission("Maintainer", $document.getId(), $document.getVnum()))

I've stumbled over this so many times, I basically gave up writing
short cuts just to avoid the errors.

	Regards
		Henning

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen       -- Geschaeftsfuehrer
INTERMETA - Gesellschaft fuer Mehrwertdienste mbH     hps@intermeta.de

Am Schwabachgrund 22  Fon.: 09131 / 50654-0   info@intermeta.de
D-91054 Buckenhof     Fax.: 09131 / 50654-20   

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


Re: I give up!

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 11/16/01 6:59 PM, "Stephane MOR" <st...@yahoo.fr> wrote:

> Hi,
> 
> I read somewhere (must be "User's Guide", or "VTL Reference", at
> http://jakarta.apache.org ), that single quotes are processed while double
> quote are treated "as is" .
> 
> I am not sure whether it is for the #if statement, or something else, but I
> think this might work ...
> 
> This would give something like :
> if ($user.hasDocPermission("Maintainer", '$document.id','$document.vnum'))
> 
> I hope it helps, and NEVER give up !

The downside to that would be that the string '$document.id' would be passed
into the method...

Geir

> 
> Stephane
> 
> ----- Original Message -----
> From: "Colm McCartan" <co...@owl.co.uk>
> To: "Velocity Users List" <ve...@jakarta.apache.org>
> Sent: Thursday, November 15, 2001 6:55 PM
> Subject: I give up!
> 
> 
>> Hello all,
>> 
>> OK, I'm certain this has been asked several times and that how to do is
> buried
>> in the ref manual somewhere but I can't find this in the archive and its
> driving
>> me mad trying to figure it out:
>> 
>> I'm trying to call an object method from within an if statement in a
> template
>> like so, e.g.:
>> 
>> if ($user.hasDocPermission("Maintainer", "$document.id", $document.vnum))
>> 
>> but it fails to even hit the method (to my surprise, Velocity doesn't
> complain
>> about type mismatching, invalid referencing or anything, just fails
> silently)
>> 
>> If I hard-wire it like so:
>> 
>> if ($user.hasDocPermission("Maintainer", "abc12de", 1))
>> 
>> it works a treat...
>> 
>> My tiny mind is failing to understand something to do with escaping the
> quotes
>> here I think but I'd be grateful if anyone could point out what..
>> 
>> Could I perhaps use a directive to build the argument list first? I would
> then
>> need to know how to escape a double quote in a set directive, yes? My
> various
>> (horrific looking) attempts at this are throwing all sorts of parse
>> exceptions...
>> 
>> Thanks a lot for any help...
>> colm
>> 
>> 
>> 
>> --
>> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
>> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 
> 
> _________________________________________________________
> 
> Do You Yahoo!?
> 
> Get your free @yahoo.com address at http://mail.yahoo.com
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin



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


Re: I give up!

Posted by Stephane MOR <st...@yahoo.fr>.
Hi,

I read somewhere (must be "User's Guide", or "VTL Reference", at
http://jakarta.apache.org ), that single quotes are processed while double
quote are treated "as is" .

I am not sure whether it is for the #if statement, or something else, but I
think this might work ...

This would give something like :
 if ($user.hasDocPermission("Maintainer", '$document.id','$document.vnum'))

I hope it helps, and NEVER give up !

Stephane

----- Original Message -----
From: "Colm McCartan" <co...@owl.co.uk>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Thursday, November 15, 2001 6:55 PM
Subject: I give up!


> Hello all,
>
> OK, I'm certain this has been asked several times and that how to do is
buried
> in the ref manual somewhere but I can't find this in the archive and its
driving
> me mad trying to figure it out:
>
> I'm trying to call an object method from within an if statement in a
template
> like so, e.g.:
>
> if ($user.hasDocPermission("Maintainer", "$document.id", $document.vnum))
>
> but it fails to even hit the method (to my surprise, Velocity doesn't
complain
> about type mismatching, invalid referencing or anything, just fails
silently)
>
> If I hard-wire it like so:
>
> if ($user.hasDocPermission("Maintainer", "abc12de", 1))
>
> it works a treat...
>
> My tiny mind is failing to understand something to do with escaping the
quotes
> here I think but I'd be grateful if anyone could point out what..
>
> Could I perhaps use a directive to build the argument list first? I would
then
> need to know how to escape a double quote in a set directive, yes? My
various
> (horrific looking) attempts at this are throwing all sorts of parse
> exceptions...
>
> Thanks a lot for any help...
> colm
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


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