何时使用 f:view 和 f:subview
我不确定使用
和
有什么好处。 我注意到人们可以在不使用 JSF 页面的情况下编写它们。
使用这些标签有什么好处?
I am not sure what are the benefits of using <f:view>
and <f:subview>
.
I noticed that one could write JSF pages without using them.
What are the benefits of using those tags?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
;
仅当您想要显式指定/覆盖任何可用属性(例如locale
、encoding
、contentType< /代码>等或者想要附加一些阶段侦听器。例如
,如果您不指定它,则将仅使用合理的 JSF 默认值,分别是
UIViewRoot#getLocale()
、UTF-8
和最接近的匹配Accept
请求标头。应该注意的是,Accept
请求标头的最接近匹配并不总是完全正确。有时,它会导致application/xhtml+xml
,因为在 Facelets 的情况下,URL 中存在.xhtml
扩展名,并且 Web 浏览器未配置为将其解释为text/html(如MSIE)。您确实希望通过显式将其设置为
text/html
来避免这种错误的内容类型。请注意,将其放在模板中的位置并不重要。您甚至可以将其作为
的直接子级放入模板客户端中。但是,规范位置是的直接子级,因此包装
和
>。这也是在遗留 JSP 中实际需要的实现方式。在 Facelets 中,它是可选的并被视为元数据。另请参阅:
;
将创建另一个命名容器上下文。当您想要重用包含文件(该文件又在同一视图根目录中多次包含固定组件 ID)时,这特别有用,否则您将收到重复的组件 ID 错误。然而,从 JSF 2.0 开始,这样的包含文件可以更好地成为一个复合组件,它本身已经是一个命名容器。如果您不指定它,那么如果您不在视图中多次重复使用具有相同 ID 的物理组件,也不会造成损害。
另请参阅:
<f:view>
The
<f:view>
is only useful if you want to explicitly specify/override any of the available attributes such aslocale
,encoding
,contentType
, etc or want to attach some phase listeners. E.g.If you don't specify it, then the sane JSF defaults will just be used instead, which is respectively
UIViewRoot#getLocale()
,UTF-8
and the closest match ofAccept
request header. Noted should be that the closest match ofAccept
request header isn't always entirely right. Sometimes it results inapplication/xhtml+xml
because of the presence of.xhtml
extension in the URL in case of Facelets and the webbrowser not being configured to interpret it astext/html
by default (like MSIE). You'd really like to avoid this wrong content type by explicitly setting it totext/html
.Note that it doesn't matter where you put it in the template. You can even put it in template client as immediate child of
<ui:define>
. However, canonical place is as immediate child of<html>
and thus wrapping both<h:head>
and<h:body>
. This is also the way how it's done in legacy JSP where it's actually required. In Facelets it's optional and accounted as meta data.See also:
<f:subview>
The
<f:subview>
will create another naming container context. This is particularly useful when you want to reuse an include file which in turn contain fixed component IDs more than once in the same view root, otherwise you will get duplicate component ID errors. However, since JSF 2.0 such an include file can better be a composite component which is by itself already a naming container.If you don't specify it, then it won't harm if you don't reuse a component with the same ID physically multiple times in the view.
See also: