何时使用 f:view 和 f:subview [英] When to use f:view and f:subview

查看:23
本文介绍了何时使用 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?

推荐答案

<f:view> 仅在您想显式指定/覆盖任何可用属性时有用,例如 localeencodingcontentType 等或想要附加一些阶段侦听器.例如

<f:view>

The <f:view> is only useful if you want to explicitly specify/override any of the available attributes such as locale, encoding, contentType, etc or want to attach some phase listeners. E.g.

<f:view locale="#{user.locale}" encoding="UTF-8" contentType="text/html">

如果你不指定它,那么将使用正常的 JSF 默认值,分别是 UIViewRoot#getLocale()UTF-8Accept 请求标头的最接近匹配.应该注意的是,Accept 请求标头的最接近匹配并不总是完全正确.有时它会导致 application/xhtml+xml 因为在 URL 中存在 .xhtml 扩展名,以防 Facelets 和 webbrowser 未配置为将其解释为 text/html 默认情况下(如 MSIE).您真的很想通过将其显式设置为 text/html 来避免这种错误的内容类型.

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 of Accept request header. Noted should be that the closest match of Accept request header isn't always entirely right. Sometimes it results in application/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 as text/html by default (like MSIE). You'd really like to avoid this wrong content type by explicitly setting it to text/html.

请注意,将它放在模板中的哪个位置并不重要.您甚至可以将其作为 的直接子项放在模板客户端中.但是,规范位置是 的直接子元素,因此将 包装起来>.这也是它在实际需要的传统 JSP 中的完成方式.在 Facelets 中,它是可选的,并被视为元数据.

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.

<f:subview> 将创建另一个命名容器上下文.当您想要重用包含文件而该文件又在同一视图根中多次包含固定组件 ID 时,这特别有用,否则您将收到重复的组件 ID 错误.但是,由于 JSF 2.0,这样的包含文件最好是一个复合组件,它本身已经是一个命名容器.

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.

如果你不指定它,那么如果你不在视图中多次物理重用具有相同 ID 的组件也不会造成伤害.

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.

这篇关于何时使用 f:view 和 f:subview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆