Process template from java backed webscript
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2014 04:04 PM
Hi all!
I have java backed webscript and i need to process FreeMarker template file against the node in Java, using JavaScript it can be achieved using the following code:
How can i do the same thing in Java? I've tried create ScriptNode manually and call processTemplate method but i don't have scope object and when i call processTemplate i have NullPointerException.
Is there some solutions to solve it?
Thanks in advance!
I have java backed webscript and i need to process FreeMarker template file against the node in Java, using JavaScript it can be achieved using the following code:
document.processTemplate(template)
How can i do the same thing in Java? I've tried create ScriptNode manually and call processTemplate method but i don't have scope object and when i call processTemplate i have NullPointerException.
Is there some solutions to solve it?
Thanks in advance!
Labels:
- Labels:
-
Archive
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2014 03:19 AM
You can use TemplateService APIs to achieve same.
public void processTemplateString(String engine,
String template,
Object model,
Writer out)
throws TemplateException
public void processTemplateString(String engine,
String template,
Object model,
Writer out)
throws TemplateException
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2014 09:48 AM
Sorry for such a long reply, thx <b>mitpatoliya</b> it works.
if anyone is interested, here is example of usage:
and also template example
if anyone is interested, here is example of usage:
TemplateService templateService = serviceRegistry.getTemplateService();// our modelMap<String, Object> model = new HashMap<String, Object>(8, 1.0f);// modelNodeRef is the node where from we are gonna take valuesmodel.put("document", new TemplateNode(modelNodeRef, serviceRegistry, null));// TemplateNode allows go get node properties, assocs etc.
and also template example
<#assign props=document.getProperties()>${props["cm:name"]
