Last modified by Vincent Massol on 2016/09/28

From version 27.1
edited by Thomas Mortagne
on 2016/08/19
Change comment: There is no comment for this version
To version 28.1
edited by Thomas Mortagne
on 2016/08/19
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -53,6 +53,34 @@
53 53  
54 54  = For Developers =
55 55  
56 +== Velocity and Script context improvements ==
57 +
58 +##VelocityContext## and ##ScriptContext## are here since a long time and were not fully a sync leading to many hack having to deal with both (and often forgetting one of the other).
59 +
60 +They are now fully in synch (and if you find a use case where it's not true create a BUG on http://jira.xwiki.org) and VelocityContext is now close to internal detail. From now on if you want to set some binding for whatever script is going to be executed next you should to it trough ##ScriptContext## and completely forget that ##VelocityContext## ever existed in most cases.
61 +
62 +New APIs to help with that:
63 +
64 +* ##VelocityManager#evaluate(Writer out, String templateName, Reader source)## which execute the passed velocity content with the passed template name and write the result in the passed Writer. This method deal with ##VelocityContext## internally
65 +* ##ScriptContextManager#getCurrentScriptContext()## should be used when you want to SET something in the current script context so that it end up in a script that might be executed later
66 +* ##ScriptContextManager#getScriptContext()## is not new but should be used only if you want to get the ##ScriptContext## exactly as a script would get it (to see if it contains something you want to access), this should be a rare use case.
67 +
68 +Another consequence of this is that you can (finally) do things like:
69 +
70 +{{code}}
71 +{{velocity}}
72 +## Setting some script binding in Velocity
73 +#set($myvar = "toto")
74 +{{/velocity}}
75 +
76 +{{groovy}}
77 +// Lets use the script binding that has been set in previous script
78 +print myvar
79 +{{/groovy}}
80 +{{/code}}
81 +
82 +The opposite was already possible but there was some limitations, for example it was impossible to overwrite in groovy a binding that was already in the ##VelocityContext##.
83 +
56 56  == Filter framework improvements ==
57 57  
58 58  Thanks to now Java 8 support getting methods parameters names trough reflexion it's not required anymore to use ##@Name## annotation in the definition of a filter. See [[extensions:Extension.Filter Module||anchor="#HAnnotations"]] for more details.

Get Connected