【问题标题】:Unable to get values in ftl from value stack in custom Result Type无法从自定义结果类型的值堆栈中获取 ftl 中的值
【发布时间】:2011-01-27 04:34:50
【问题描述】:

我无法从 FTL 文件的值堆栈中检索值。这是代码。

Action 类拥有一个名为 '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 代码:

${name}

自定义结果类型doExecute方法

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);

我正在传递包含最近执行的 Action 的值 Stack。但是FTL抛出异常

sample.ftl 中第 1 行第 3 列的表达式名称未定义

我尝试使用传递会话而不是值堆栈,我可以在 FTL 中获取值。

请建议我一种从值堆栈中将值从 Action 类获取到 FTL 的方法。 提前谢谢。

【问题讨论】:

    标签: templates freemarker


    【解决方案1】:

    我有一种方法可以从最近执行的动作类中获取值。只需将最后一条语句更改如下

    template.process(invocation.getAction(), out);
    

    谢谢

    【讨论】:

      猜你喜欢
      • 2015-05-16
      • 1970-01-01
      • 2014-12-30
      • 1970-01-01
      • 2016-04-03
      • 2011-03-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-06
      相关资源
      最近更新 更多