f:importConstants
在复合组件内部使用的最佳方法是什么?你不能放在f:metadata
那里,那么这里最好的解决方法是什么?在 Omnifaces 和o:importConstants
JSF 2.2 中,这没有问题,它在任何地方都被允许,即使在复合组件中也是如此。
提前致谢 :)
由于<f:importConstants>
必须是 的子级<f:metadata>
(又必须是 的子级),因此它必须使用与官方文档<f:view>
中描述的相同的合成模式:
The implementation must allow templating for this element according
to the following pattern.
template client XHTML view, view01.xhtml
<ui:composition template="template.xhtml">
<ui:define name="metadata">
<f:metadata>
<f:viewParam name="id"/>
</f:metadata>
</ui:define>
<ui:define name="content">
<h1>The big news stories of the day</h1>
</ui:define>
</ui:composition>
Note line 4. The page author must ensure that the <f:metadata> element does not
appear on a template or included page. It must reside on the root page that
corresponds to the viewId.
The template page, template.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xml:lang="en" lang="en">
<body>
<f:view>
<ui:insert name="metadata"/>
<div id="container">
<ui:insert name="content"/>
</div>
</f:view>
</body>
</html>