自定义HTML标记属性不是由JSF呈现的 [英] Custom HTML tag attributes are not rendered by JSF
问题描述
我想为我的登录表单添加一些iOS特定的标签属性。如果我看看我的网页源代码,autocorrect,autocapitalize和拼写检查的属性就不存在了。这是什么原因?
< h:inputText id =user-nameforceId =truevalue =#{login.username}style =width:120px;
autocorrect =offautocapitalize =offspellcheck =false/>
这是设计。您只能指定属性由JSF组件本身支持(即,它已列在标签文档)。您不能指定任意的附加属性,它们将被全部忽略。
有几种方法可以解决这个问题:
-
< html ... xmlns:a =http://xmlns.jcp.org/jsf/passthrough>
...
< h:inputText ... a:autocorrect =off/>
(注意我使用
xmlns:a
代替xmlns:p
以避免与PrimeFaces默认命名空间冲突)
或者:
$ b< html ... xmlns:f =http:// xmlns。 jcp.org/jsf/core\">
...
< h:inputText ...>
< / h:inputText>
-
使用 OmniFaces
Html5RenderKit
。自1.5版本以来,它支持通过< context-param>
指定自定义属性。另请参阅展示范例或 Javadoc 。
创建一个自定义的渲染器。你可以在下面的答案中找到几个具体的例子:
b $ b - 如何呈现自定义属性< h:outputLink> ;?
-
- 添加自定义属性到JSF中的Primefaces自动完成组件
I want to add some iOS specific tag attributes to my login-form. If I have a look on my web page source, the attributes autocorrect, autocapitalize and spellcheck aren't there. What is the reason for this? I am using JSF 2.x.
<h:inputText id="user-name" forceId="true" value="#{login.username}" style="width:120px;"
autocorrect="off" autocapitalize="off" spellcheck="false" />
This is by design. You can only specify attributes which are supported by the JSF component itself (i.e. it's listed in the attribute list in the tag documentation). You can't specify arbitrary additional attributes, they will all be plain ignored.
There are several ways to solve this:
If you're already on JSF 2.2+, simply specify it as passthrough attribute:
<html ... xmlns:a="http://xmlns.jcp.org/jsf/passthrough"> ... <h:inputText ... a:autocorrect="off" />
(note that I'm using
xmlns:a
instead ofxmlns:p
to avoid clash with PrimeFaces default namespace)Or:
<html ... xmlns:f="http://xmlns.jcp.org/jsf/core"> ... <h:inputText ...> <f:passThroughAttribute name="autocorrect" value="off" /> </h:inputText>
Use OmniFaces
Html5RenderKit
. Since the 1.5 release, it supports specifying custom attributes by<context-param>
. See also the showcase example or Javadoc.Create a custom renderer. You can find several concrete examples in below answers:
这篇关于自定义HTML标记属性不是由JSF呈现的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!