JSF 2中支持纯HTML 5标记 [英] Pure HTML 5 tag support in JSF 2

查看:383
本文介绍了JSF 2中支持纯HTML 5标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的JSF页面中使用纯HTML5,因为某些UI功能无法通过JSF2提供的HTML支持来实现。



$ hr

在JSF 2.0中,HTML 5表单元素的某些属性无法在标准JSF输入组件中正确呈现。



例如, < code>< h:inputText type =email

$ b $不能呈现< input type =email b

在下面给出的链接,他们使用了一些纯HTML 5标签,例如< canvas> <报头GT; <页脚> < small> 等等。



现在我的问题是:


  1. 当我尝试在JSF页面中使用类型为text的纯html输入标记时,无法从我的Managed Bean中检索值并将其设置为该文本框。为什么没有显示这个值?

  2. >


解决方案

HTML5支持添加到JSF2.2中。从那以后,您可以将直通属性添加到JSF组件:

 < html xmlns =http://www.w3。 org / 1999 / xhtml
xmlns:h =http://java.sun.com/jsf/html
xmlns:p =http://java.sun.com/jsf/直通>
< h:form>
< h:inputText p:type =email/>
< / h:表格>
< / html>

JSF(2.0和2.2)将忽略未知的属性。如果您需要使用JSF2.0呈现HTML5属性,则可以使用 Omnifaces HTML5 Renderkit



纯粹的HTML标签只是纯粹的HTML标签。他们不是JSF组件。因此它们将被呈现给视图,但JSF将不关心它们并且不会更新您的模型。



JSF2.2也带有 Passthrough Elements 。现在可以将HTML标签转换为JSF组件:

 < html xmlns =http:// www .w3.org / 1999 / xhtml
xmlns:jsf =http://java.sun.com/jsf
xmlns:f =http://java.sun.com/jsf /芯>
< input jsf:id =footype =textjsf:value =#{bean.bar}>
< / html>

JSF知道有一个相应的UIComponent ,并将这个HTML-Tag转换为ah:inputText。如果没有相应的UIComponent,JSF将创建一个支持ajax的特殊的。



另见: JSF 2.2:HTML5友好标记


I want to use plain HTML 5 in my JSF page as some UI functionality cannot be achieved by HTML support provided by JSF2.


In JSF 2.0, some attributes of HTML 5 form elements cannot be rendered correctly in the standard JSF input components.

For eg,<input type="email" cannot be rendered by <h:inputText type="email".

In the below given link, they have used some pure HTML 5 tags like <canvas> <header> <footer> <small> etc.

Now my questions are:

  1. When I try to use the pure html input tag with type "text" in my JSF page, I cant able to retrieve the value from my Managed Bean and set it to this text box. why the value is not displayed?

  2. Only some plain HTML 5 tags will be supported in xhtml page or all the plain HTML 5 tags will be supported

解决方案

HTML5 Support was added in JSF2.2. Since then you can add passthrough Attributes to JSF-Components:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://java.sun.com/jsf/passthrough">
  <h:form>
    <h:inputText p:type="email" />
  </h:form>
</html>

Attributes which are not known will be ignored by JSF (2.0 and 2.2). If you need to render HTML5-Attributes with JSF2.0 you can use Omnifaces HTML5 Renderkit.

Pure HTML-Tags are just pure HTML-Tags. They are no JSF components. So they will be rendered to the view but JSF won't care about them and won't update your Model.

JSF2.2 came also with Passthrough Elements. Now it's possible to turn a HTML-Tag to a JSF-Component:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:jsf="http://java.sun.com/jsf" 
  xmlns:f="http://java.sun.com/jsf/core">
  <input jsf:id="foo" type="text" jsf:value="#{bean.bar}">
</html>

JSF knows that there is a corresponding UIComponent and will convert this HTML-Tag to a h:inputText. If there is no corresponding UIComponent JSF will create a special one which supports ajax.

See also: JSF 2.2: HTML5 friendly markup

这篇关于JSF 2中支持纯HTML 5标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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