Created
June 27, 2017 05:10
-
-
Save calvincodes/dbf99cc19c41d8df3e63d0c6e5d3f309 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices(); | |
// renderKeyValueMap comprises of the java object(s) reference in | |
// velocity template as keys and java object(s) as values | |
VelocityContext velocityContext = new VelocityContext(renderKeyValueMap); | |
// Incorrect way of passing a custom template string for rendering | |
// Note that templateBody is pre-fetched from the database | |
StringReader reader = new StringReader(templateBody); | |
SimpleNode node = runtimeServices.parse(reader, templateBody); | |
Template template = new Template(); | |
template.setRuntimeServices(runtimeServices); | |
template.setData(node); | |
template.initDocument(); | |
StringWriter populatedVelocityTemplate = new StringWriter(); | |
template.merge(velocityContext, populatedVelocityTemplate); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment