Polish script templating documentation

This commit is contained in:
Sebastien Deleuze
2015-07-23 23:39:02 +02:00
parent 2a995ae246
commit 8e5244ac3d
3 changed files with 21 additions and 9 deletions

View File

@@ -26,10 +26,8 @@ import javax.script.ScriptEngine;
* <pre class="code">
*
* // Add the following to an &#64;Configuration class
*
* &#64;Bean
* public ScriptTemplateConfigurer mustacheConfigurer() {
*
* ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer();
* configurer.setEngineName("nashorn");
* configurer.setScripts("mustache.js");
@@ -39,9 +37,9 @@ import javax.script.ScriptEngine;
* }
* </pre>
*
* <p><b>NOTE:</b> It is possible to use non thread-safe script engines and
* templating libraries, like Handlebars or React running on Nashorn, by setting
* the {@link #setSharedEngine sharedEngine} property to {@code false}.
* <p><b>NOTE:</b> It is possible to use non thread-safe script engines with
* templating libraries not designed for concurrency, like Handlebars or React running on
* Nashorn, by setting the {@link #setSharedEngine sharedEngine} property to {@code false}.
*
* @author Sebastien Deleuze
* @since 4.2
@@ -102,8 +100,10 @@ public class ScriptTemplateConfigurer implements ScriptTemplateConfig {
/**
* When set to {@code false}, use thread-local {@link ScriptEngine} instances instead
* of one single shared instance. This flag should be set to {@code false} for those
* using non thread-safe script engines and templating libraries, like Handlebars or
* React running on Nashorn for example.
* using non thread-safe script engines with templating libraries not designed for
* concurrency, like Handlebars or React running on Nashorn for example.
* In this case, Java 8u60 or greater is required due to
* <a href="https://bugs.openjdk.java.net/browse/JDK-8076099">this bug</a>.
* <p>When this flag is set to {@code false}, the script engine must be specified using
* {@link #setEngineName(String)}. Using {@link #setEngine(ScriptEngine)} is not
* possible because multiple instances of the script engine need to be created lazily

View File

@@ -1265,7 +1265,9 @@
<xsd:documentation><![CDATA[
When set to false, use thread-local ScriptEngine instances instead of one single shared
instance. This flag should be set to false for those using non thread-safe script engines
and templating libraries, like Handlebars or React running on Nashorn for example.
with templating libraries not designed for concurrency, like Handlebars or React
running on Nashorn for example. In this case, Java 8u60 or greater is required due to
this bug: https://bugs.openjdk.java.net/browse/JDK-8076099.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>

View File

@@ -1489,7 +1489,8 @@ It has been tested with:
To be able to use script templates integration, you need to have available in your classpath
the script engine:
* http://openjdk.java.net/projects/nashorn/[Nashorn] Javascript engine is provided builtin with Java 8+
* http://openjdk.java.net/projects/nashorn/[Nashorn] Javascript engine is provided builtin with Java 8+.
Using the latest update release available is highly recommended.
* http://docs.oracle.com/javase/7/docs/technotes/guides/scripting/programmer_guide/#jsengine[Rhino]
Javascript engine is provided builtin with Java 6 and Java 7.
Please notice that using Rhino is not recommended since it does not
@@ -1617,11 +1618,20 @@ browser facilities not available in the server-side script engine.
configurer.setEngineName("nashorn");
configurer.setScripts("polyfill.js", "handlebars.js", "render.js");
configurer.setRenderFunction("render");
configurer.setSharedEngine(false);
return configurer;
}
}
----
[NOTE]
====
Setting the `sharedEngine` property to `false` is required when using non thread-safe
script engines with templating libraries not designed for concurrency, like Handlebars or
React running on Nashorn for example. In that case, Java 8u60 or greater is required due
to https://bugs.openjdk.java.net/browse/JDK-8076099[this bug].
====
`polyfill.js` only defines the `window` object needed by Handlebars to run properly:
[source,javascript,indent=0]