I have a requirement to process freemarker ftl file on server side and return back the HTML to the client. I would like to know if it is possible to process freemaker template having
struts tags in it using template.process().
Action class code
// Configuration created from struts2 freemarkermanager FreemarkerManager freeMarkerManager = new FreemarkerManager(); Configuration config = freeMarkerManager.getConfiguration(context);
//Configuration without any specific settings. Configuration config = new Configuration(); //Tried both nothing works.
Template template = config.getTemplate("TEMPLATE PATH");
Map<
String, Object> inputMap = new HashMap<String, Object>(); inputMap.put("document", document);
StringWriter output = new StringWriter(); template.process(inputMap, output);
Freemarker template: <#assign s=JspTaglibs["/struts-tags"]> <table> <tr> <th><@s.text name="Document Name"/></th> <th><@s.text name="Description"/></th> </tr>
`<@s.iterator value="inspiration" status="status">`
`<tr>`
`<td class="nowrap"><@s.property value="properties.DOCUMENT_NAME"/></td>`
`<td class="nowrap"><@s.property value="properties.DESCRIPTION"/></td>`
`</tr>`
`</@s.iterator>`
`</table>`
I have also added struts-tags.tld under web-inf folder.
Exception
freemarker.core.InvalidReferenceException: Expression JspTaglibs is undefined on line 1,
If I remove <#assign s=JspTaglibs["/struts-tags"]>
freemarker.core.InvalidReferenceException: Expression s is undefined on line 7
Thanks in advance, Chethan