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

查看:320
本文介绍了何时使用f:view和f:subview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定使用<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>

<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-8和最接近的Accept请求标头.请注意,Accept请求标头的最接近匹配并不总是完全正确.有时,由于在Facelets情况下URL中存在.xhtml扩展名,并且默认情况下未将Web浏览器配置为将其解释为text/html(例如MSIE),因此会导致application/xhtml+xml.您确实希望通过将其明确设置为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.

请注意,将其放置在模板中的位置无关紧要.您甚至可以将其作为<ui:define>的直接子级放在模板客户端中.但是,规范位置是<html>的直接子元素,因此包装了<h:head><h:body>.这也是在实际上必需的旧式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.

  • Our XHTML wiki page
  • Is it possible to use JSF+Facelets with HTML 4/5?
  • JSF 2.0 not rendering any page

<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.

  • Why <h:panelGroup> id is not found when I access through <f:subview> tag?
  • Binding attribute causes duplicate component ID found in the view
  • Difference between <f:subview> and <ui:composition> tags

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

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