You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by ke...@relevanz.com on 2002/12/06 04:53:29 UTC

[jelly] velocity->jelly mapping for #set

I'm trying to figure out how the #set velocity directive maps to a 
jelly expression.

In Velocity, we're accustomed to using in our templates

Example 1
#set ($foo = 1)
${foo} (formal notation)
$foo

or

Example 2
${foo.size()} ## $foo is a vector placed into the context


Looking at the core taglibs, I tried Ex 1 using 

<j:set var="foo" value="1"/>, <j:set var="foo" value="${1}"/> with no 
luck.
Only
<j:set var="foo">1</j:set> 
worked for me. Looking at the taglib doc, it says that the value attr 
accepts an Expression. Is there any shorthand for this, other than 
wrapping them in tags every single time? It's a pretty big difference 
bet

#set ($foo = 1) 
and 
<j:set var="foo">1</j:set>

For Ex 2, I believe ${foo.size()} doesn't work coz it returns a 
primitive. Is there any easy workaround? 

For Ex 3, trying 
<j:set var="foo" value="${bar.class}"/> or <j:set var="foo" 
value="${bar.getClass()}"/> (aren't these Expressions?), and again 
encapsulating the ${bar.class} within the <j:set> tags worked.

Just trying to make sure I understand how stuff is supposed to be 
used.

Thanks!

Kelvin


Re: [jelly] velocity->jelly mapping for #set

Posted by James Strachan <ja...@yahoo.co.uk>.
There are a few options here.

First off you can do Velocity-like things like add helper objects to the
context to give you access to methods on these objects via the expression
language. ${foo.doSomething(23)}

In Jelly 'macros' tend to equate to tags. Here you have a few choices.

* you could write new tags in Java code. e.g.

http://jakarta.apache.org/commons/sandbox/jelly/faq.html#adding-taglibs

Or you can implement tags in Jelly script. Here you have a few choices.

* You can use <define:taglib> and <define:tag> to create a new library using
purely Jelly scripts. Inside a <define:taglib> you can bind beans to tags
via <define:bean> or <define:jellybean>, the latter invoking a 'doIt' method
on the bean (like an execute() method on a task or run() method on a
Runnable etc).

* you can just create a script variable via <define:script> to be invoked
later via <define:invoke>.

e.g.

<define:script var="foo">
    <!-- do something here -->
</define:script>

then later...

<define:invoke script="${foo}"/>

* a final option is just to use <j:include uri="whatever.jelly"/> to
refactor common blocks of Jelly script into a single file.

James
-------
http://radio.weblogs.com/0112098/
----- Original Message -----
From: "Kelvin Tan" <ke...@relevanz.com>
To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
Sent: Monday, December 09, 2002 10:27 AM
Subject: Re: [jelly] velocity->jelly mapping for #set


Thanks James.

What about Velocimacros then? :) OK, as you've probably figured by
now, I'm wondering how to convert my existing Velocity-base app to
Jelly...

Let's see.

#set -> <j:set>
#include and #parse roughly -> <j:import>
#macro really REALLY approximately -> <j:define> yes? I guess coupled
with <j:scope> too.

Is there scope above the script level, like global macros in
Velocity? What about separation between inline and global script
definitions...

Its simple enough to define tag libraries which replace some VMs, but
not all, I should think, or am I wrong here? Perhaps there's a need
for a Velocity -> Jelly migration doc...:)

Kelvin


On Sat, 7 Dec 2002 11:43:57 -0000, James Strachan said:
>Hi Kelvin
>
>You're understanding is correct. Both
>
><j:set var="foo" value="1"/>
>
>or
>
><j:set var="foo" value="${1}"/>
>
>or
>
><j:set var="foo">1</j:set>
>
>should all work.
>
>Bear in mind though that there is currently a bug in Jexl with
>${foo.size()}. Right now the following works ${size(foo)} -
>hopefully this bug in Jexl will get fixed soon.
>
>To see the <j:set> tag in action you could take a look at the
>JellyUnit test case
>
>http://cvs.apache.org/viewcvs/jakarta-commons-
>sandbox/jelly/src/test/org/apa
>che/commons/jelly/suite.jelly?rev=HEAD
>
>James -------
>http://radio.weblogs.com/0112098/ ----- Original Message -----
>From: <ke...@relevanz.com> To: <commons-
>user@jakarta.apache.org> Sent: Friday, December 06, 2002 3:53 AM
>Subject: [jelly] velocity->jelly mapping for #set
>
>
>I'm trying to figure out how the #set velocity directive maps to a
>jelly expression.
>
>In Velocity, we're accustomed to using in our templates
>
>Example 1 #set ($foo = 1) ${foo} (formal notation) $foo
>
>or
>
>Example 2 ${foo.size()} ## $foo is a vector placed into the context
>
>
>Looking at the core taglibs, I tried Ex 1 using
>
><j:set var="foo" value="1"/>, <j:set var="foo" value="${1}"/> with
>no luck.
>Only <j:set var="foo">1</j:set> worked for me. Looking at the taglib
>doc, it says that the value attr accepts an Expression. Is there any
>shorthand for this, other than wrapping them in tags every single
>time? It's a pretty big difference bet
>
>#set ($foo = 1) and <j:set var="foo">1</j:set>
>
>For Ex 2, I believe ${foo.size()} doesn't work coz it returns a
>primitive. Is there any easy workaround?
>
>For Ex 3, trying <j:set var="foo" value="${bar.class}"/> or <j:set
>var="foo" value="${bar.getClass()}"/> (aren't these Expressions?),
>and again encapsulating the ${bar.class} within the <j:set> tags
>worked.
>
>Just trying to make sure I understand how stuff is supposed to be
>used.
>
>Thanks!
>
>Kelvin
>
>
>--
>To unsubscribe, e-mail: <mailto:commons-user-
>unsubscribe@jakarta.apache.org> For additional commands, e-mail:
><ma...@jakarta.apache.org>
>
>__________________________________________________ Do You Yahoo!?
>Everything you'll ever need on one web page from News and Sport to
>Email and Music Charts http://uk.my.yahoo.com
>
>--
>To unsubscribe, e-mail:   <mailto:commons-user-
>unsubscribe@jakarta.apache.org> For additional commands, e-mail:
><mailto:commons-user-
>help@jakarta.apache.org>




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

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Re: [jelly] velocity->jelly mapping for #set

Posted by Kelvin Tan <ke...@relevanz.com>.
Thanks James.

What about Velocimacros then? :) OK, as you've probably figured by 
now, I'm wondering how to convert my existing Velocity-base app to 
Jelly...

Let's see. 

#set -> <j:set>
#include and #parse roughly -> <j:import>
#macro really REALLY approximately -> <j:define> yes? I guess coupled 
with <j:scope> too.

Is there scope above the script level, like global macros in 
Velocity? What about separation between inline and global script 
definitions...

Its simple enough to define tag libraries which replace some VMs, but 
not all, I should think, or am I wrong here? Perhaps there's a need 
for a Velocity -> Jelly migration doc...:) 

Kelvin


On Sat, 7 Dec 2002 11:43:57 -0000, James Strachan said:
>Hi Kelvin
>
>You're understanding is correct. Both
>
><j:set var="foo" value="1"/>
>
>or
>
><j:set var="foo" value="${1}"/>
>
>or
>
><j:set var="foo">1</j:set>
>
>should all work.
>
>Bear in mind though that there is currently a bug in Jexl with
>${foo.size()}. Right now the following works ${size(foo)} -
>hopefully this bug in Jexl will get fixed soon.
>
>To see the <j:set> tag in action you could take a look at the
>JellyUnit test case
>
>http://cvs.apache.org/viewcvs/jakarta-commons-
>sandbox/jelly/src/test/org/apa
>che/commons/jelly/suite.jelly?rev=HEAD
>
>James -------
>http://radio.weblogs.com/0112098/ ----- Original Message -----
>From: <ke...@relevanz.com> To: <commons-
>user@jakarta.apache.org> Sent: Friday, December 06, 2002 3:53 AM
>Subject: [jelly] velocity->jelly mapping for #set
>
>
>I'm trying to figure out how the #set velocity directive maps to a
>jelly expression.
>
>In Velocity, we're accustomed to using in our templates
>
>Example 1 #set ($foo = 1) ${foo} (formal notation) $foo
>
>or
>
>Example 2 ${foo.size()} ## $foo is a vector placed into the context
>
>
>Looking at the core taglibs, I tried Ex 1 using
>
><j:set var="foo" value="1"/>, <j:set var="foo" value="${1}"/> with
>no luck.
>Only <j:set var="foo">1</j:set> worked for me. Looking at the taglib
>doc, it says that the value attr accepts an Expression. Is there any
>shorthand for this, other than wrapping them in tags every single
>time? It's a pretty big difference bet
>
>#set ($foo = 1) and <j:set var="foo">1</j:set>
>
>For Ex 2, I believe ${foo.size()} doesn't work coz it returns a
>primitive. Is there any easy workaround?
>
>For Ex 3, trying <j:set var="foo" value="${bar.class}"/> or <j:set
>var="foo" value="${bar.getClass()}"/> (aren't these Expressions?),
>and again encapsulating the ${bar.class} within the <j:set> tags
>worked.
>
>Just trying to make sure I understand how stuff is supposed to be
>used.
>
>Thanks!
>
>Kelvin
>
>
>--
>To unsubscribe, e-mail: <mailto:commons-user-
>unsubscribe@jakarta.apache.org> For additional commands, e-mail:
><ma...@jakarta.apache.org>
>
>__________________________________________________ Do You Yahoo!?
>Everything you'll ever need on one web page from News and Sport to
>Email and Music Charts http://uk.my.yahoo.com
>
>--
>To unsubscribe, e-mail:   <mailto:commons-user-
>unsubscribe@jakarta.apache.org> For additional commands, e-mail:
><mailto:commons-user-
>help@jakarta.apache.org>




Re: [jelly] velocity->jelly mapping for #set

Posted by James Strachan <ja...@yahoo.co.uk>.
Hi Kelvin

You're understanding is correct. Both

<j:set var="foo" value="1"/>

or

<j:set var="foo" value="${1}"/>

or

<j:set var="foo">1</j:set>

should all work.

Bear in mind though that there is currently a bug in Jexl with
${foo.size()}. Right now the following works ${size(foo)} - hopefully this
bug in Jexl will get fixed soon.

To see the <j:set> tag in action you could take a look at the JellyUnit test
case

http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/jelly/src/test/org/apa
che/commons/jelly/suite.jelly?rev=HEAD

James
-------
http://radio.weblogs.com/0112098/
----- Original Message -----
From: <ke...@relevanz.com>
To: <co...@jakarta.apache.org>
Sent: Friday, December 06, 2002 3:53 AM
Subject: [jelly] velocity->jelly mapping for #set


I'm trying to figure out how the #set velocity directive maps to a
jelly expression.

In Velocity, we're accustomed to using in our templates

Example 1
#set ($foo = 1)
${foo} (formal notation)
$foo

or

Example 2
${foo.size()} ## $foo is a vector placed into the context


Looking at the core taglibs, I tried Ex 1 using

<j:set var="foo" value="1"/>, <j:set var="foo" value="${1}"/> with no
luck.
Only
<j:set var="foo">1</j:set>
worked for me. Looking at the taglib doc, it says that the value attr
accepts an Expression. Is there any shorthand for this, other than
wrapping them in tags every single time? It's a pretty big difference
bet

#set ($foo = 1)
and
<j:set var="foo">1</j:set>

For Ex 2, I believe ${foo.size()} doesn't work coz it returns a
primitive. Is there any easy workaround?

For Ex 3, trying
<j:set var="foo" value="${bar.class}"/> or <j:set var="foo"
value="${bar.getClass()}"/> (aren't these Expressions?), and again
encapsulating the ${bar.class} within the <j:set> tags worked.

Just trying to make sure I understand how stuff is supposed to be
used.

Thanks!

Kelvin


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

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com