[xwiki-users] Passing variables between context
Hi xwiki-users, I have a simple macro defined in velocity: {{velocity}} {{{ #macro( addDate $timeZone $date ) #set( $script = " tz = '$timeZone' date = '$date' timezone = java.util.TimeZone.getTimeZone( timezone ) cal = java.util.Calendar.getInstance( timezone ) // etc... " ) #set( $runnable = $xwiki.parseGroovyFromString( $script ) ) $runnable.run() #end }}} {{/velocity}} Currently, the velocity macro parameters $timeZone and $date have to be Strings. I want to be able to pass "real objects" rather than just strings into the groovy script, though. I can easily return an Object back into Velocity space by returning from the groovy script, but is there a way to go the other way around? I guess what I really need is some "context" object shared by groovy and Velocity... Thanks in advance!
Hi Lewis, Maybe this will help: http://platform.xwiki.org/xwiki/bin/view/DevGuide/GroovyClassHelloWorldTutor... In the shown example there are objects passed from Velocity to Groovy. -Vincent On Jul 15, 2009, at 5:30 PM, Lewis Denizen wrote:
Hi xwiki-users,
I have a simple macro defined in velocity:
{{velocity}} {{{ #macro( addDate $timeZone $date ) #set( $script = " tz = '$timeZone' date = '$date'
timezone = java.util.TimeZone.getTimeZone( timezone ) cal = java.util.Calendar.getInstance( timezone ) // etc... " )
#set( $runnable = $xwiki.parseGroovyFromString( $script ) )
$runnable.run() #end }}} {{/velocity}}
Currently, the velocity macro parameters $timeZone and $date have to be Strings. I want to be able to pass "real objects" rather than just strings into the groovy script, though. I can easily return an Object back into Velocity space by returning from the groovy script, but is there a way to go the other way around? I guess what I really need is some "context" object shared by groovy and Velocity...
Thanks in advance!
Thank you Vincent, that's exactly what I needed :-) And sorry I didn't check the tutes more carefully... Just for people that need to do this without a full-blown Groovy class: #macro( addDate $timeZone $date) #set( $script = " x = context.getClass() ... " ) #set( $runnable = $xwiki.parseGroovyFromString( $script ) ) $runnable.setProperty( "context", $context ) $runnable.setProperty( "timeZone", $timeZone ) $runnable.setProperty( "date", $date ) $runnable.run() #end On Thu, Jul 16, 2009 at 3:46 AM, Vincent Massol <[email protected]> wrote:
Hi Lewis,
Maybe this will help:
http://platform.xwiki.org/xwiki/bin/view/DevGuide/GroovyClassHelloWorldTutor...
In the shown example there are objects passed from Velocity to Groovy.
-Vincent
On Jul 15, 2009, at 5:30 PM, Lewis Denizen wrote:
Hi xwiki-users,
I have a simple macro defined in velocity:
{{velocity}} {{{ #macro( addDate $timeZone $date ) #set( $script = " tz = '$timeZone' date = '$date'
timezone = java.util.TimeZone.getTimeZone( timezone ) cal = java.util.Calendar.getInstance( timezone ) // etc... " )
#set( $runnable = $xwiki.parseGroovyFromString( $script ) )
$runnable.run() #end }}} {{/velocity}}
Currently, the velocity macro parameters $timeZone and $date have to be Strings. I want to be able to pass "real objects" rather than just strings into the groovy script, though. I can easily return an Object back into Velocity space by returning from the groovy script, but is there a way to go the other way around? I guess what I really need is some "context" object shared by groovy and Velocity...
Thanks in advance!
users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
participants (2)
-
Lewis Denizen -
Vincent Massol