Unable to get values in ftl from value stack in custom Result Type

Posted by Nagadev on Stack Overflow See other posts from Stack Overflow or by Nagadev
Published on 2010-03-13T15:43:44Z Indexed on 2010/03/13 15:45 UTC
Read the original article Hit count: 282

Filed under:
|

Hello, I am unable retrieve value from value stack in FTL file. Here is the code.

Action class holds a property called 'name'

private String name;
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}

public String execute(){
    setName("From value stack .. ");
    return SUCCESS;
}

FTL code:

${name}

Custom result Type deExecute Method

Configuration configuration = new Configuration();

String templatePath = "/ftl";
ServletContext context = ServletActionContext.getServletContext();
configuration.setServletContextForTemplateLoading(context, templatePath);
configuration.setObjectWrapper(new DefaultObjectWrapper());

Template template = configuration.getTemplate("sample.ftl");
OutputStreamWriter out = new OutputStreamWriter(System.out);
template.process(ActionContext.getContext().getValueStack(), out);

I am passing the value Stack which contains recently executed Action as well. But FTL is throwing an exception

Expression name is undefined on line 1, column 3 in sample.ftl

I tried with passing session instead of value stack and I could get the value in FTL.

Please suggest me a way to get values from Action class to FTL from value stack. Thanks inadvance.

© Stack Overflow or respective owner

Related posts about freemarker

Related posts about template