JSF2:如何使用模板实现站点范围的viewParam处理策略 [英] JSF2: how achieve site-wide viewParam handling policy using a template
问题描述
以下似乎在XHTML facelet模板中被忽略:
The following seems to be ignore inside XHTML facelet templates:
<f:metadata>
<f:viewParam name="id" value="#{backingBean.id}" />
</f:metadata>
(至少根据Glassfish2.2使用Mojarra)
(At least with Mojarra as per Glassfish2.2)
《 Java Server Faces 2.0完全参考》显示第540页:
Java Server Faces 2.0 Complete Reference says p.540:
f:metadata标记封装了用于指定以下内容的元素集 Facelet视图的元数据,因此必须是 f:view标记,可能不会出现在模板中.截至JSF2.0,唯一 该标签的目的是封装f:viewParam标签.
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页面中的每一个中都包含上述内容,这很麻烦,但是在模板中却失败了,我无法介绍视图参数处理策略.确实,我想同时兼顾所有页面通用的视图参数处理策略和对带有附加查询参数的特定页面的一些额外处理.
It is tedious for my current application to have to include the above in every one of hundreds of XHTML pages, but it fails in the template, I can't introduce view parameter handling policies. Indeed what I would like is both, a mixture of view parameter handling policies common to all pages and then some extra handling for specific pages that take additional query parameters.
很高兴提供建议,
Webel
推荐答案
不幸的是,这是 @ManagedProperty
反而.
Unfortunately, that's by spec. Your best bet is to use @ManagedProperty
instead.
public class BackingBean {
@ManagedProperty("#{param.id}")
private Long id;
// ...
}
唯一的缺点是,这没有提供使用XHTML进行声明式转换/验证的优点.如有必要,您可以在 @PostConstruct
方法.
The only disadvantage is that this doesn't offer the advantage of using declarative conversion/validation by XHTML. You can if necessary do this job in a @PostConstruct
method.
这篇关于JSF2:如何使用模板实现站点范围的viewParam处理策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!