XHTML facelet 模板中似乎忽略了以下内容:
<f:metadata>
<f:viewParam name="id" value="#{backingBean.id}" />
</f:metadata>
(至少根据 Glassfish2.2 使用 Mojarra)
Java Server Faces 2.0 完整引用第 540 页说:
The f:metadata tag encapsulates the set of elements used to specify the metadata for a Facelet view, and therefore must be a child of the f:view tag and may not appear in a template. As of JSF2.0, the only purpose of this tag is to encapsulate f:viewParam tags.
我当前的应用程序必须在数百个 XHTML 页面中的每一个中都包含上述内容,这很繁琐,但在模板中却失败了,我无法引入 View 参数处理策略。事实上,我想要的是,混合所有页面通用的 View 参数处理策略,然后对采用额外查询参数的特定页面进行一些额外处理。
很高兴得到建议,
韦贝尔
最佳答案
不幸的是,那是 by spec .你最好的选择是使用 @ManagedProperty
反而。
public class BackingBean {
@ManagedProperty("#{param.id}")
private Long id;
// ...
}
唯一的缺点是它没有提供通过 XHTML 使用声明性转换/验证的优势。如有必要,您可以在 @PostConstruct
中完成这项工作方法。
关于JSF2 : how achieve site-wide viewParam handling policy using a template,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7344056/