I'm writing a java backed webscript and need to know the correct way to pass objects to a freemarker template for rendering. Below is my simplified code. Webscript
public class SampleWebScript extends AbstractWebScript
{
public void execute(WebScriptRequest req, WebScriptResponse res)
throws IOException
{
try
{
Container c = getContainer();
Writer writer = res.getWriter();
String bar = "Hello World";
Object model = new SampleModel(bar);
String templatePath = "org/alfresco/demo/foo.ftl";
if(c.getTemplateProcessor().hasTemplate(templatePath))
{
c.getTemplateProcessor().process(templatePath,model,writer);
}
}
catch (Exception e)
{
throw new WebScriptException(e.getMessage());
}
}
private class SampleModel
{
private String message;
private SampleModel(String s)
{
this.message = s;
}
public String getMessage()
{
return message;
}
public void setMessage(String message)
{
this.message = message;
}
}
}
Freemarker Template
<?xml version="1.0" encoding="UTF-8"?>
<workflow-definitions>
<message>${message}</message>
</workflow-definitions>
I think the issue is with "model" on this line:
c.getTemplateProcessor().process(templatePath,model,writer);
When I hit this page in my browser I get this exception:
Error during processing of the template 'Expression message is undefined on line 4, column 20 in org/alfresco/demo/foo.ftl.'. Please contact your system administrator.