Unable to get values in ftl from value stack in custom Result Type
I am unable retrieve value from value stack in FTL file. Here is the code.
Ac开发者_开发知识库tion 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 doExecute 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.
I got a way to get values from recently executed Action Class. Just change the last statement as follows
template.process(invocation.getAction(), out);
Thanks
精彩评论