JSF 不呈现自定义 HTML 标记属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16666472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Custom HTML tag attributes are not rendered by JSF
提问by Jochen
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.
我想在我的登录表单中添加一些特定于 iOS 的标签属性。如果我查看我的网页源代码,属性自动更正、自动大写和拼写检查不存在。这是什么原因?我正在使用 JSF 2.x。
<h:inputText id="user-name" forceId="true" value="#{login.username}" style="width:120px;"
autocorrect="off" autocapitalize="off" spellcheck="false" />
回答by BalusC
This is by design. You can only specify attributes which are supportedby 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.
这是设计使然。您只能指定JSF 组件本身支持的属性(即它列在标签文档的属性列表中)。您不能指定任意的附加属性,它们都将被完全忽略。
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>
Create a custom renderer. You can find several concrete examples in below answers:
如果您已经使用 JSF 2.2+,只需将其指定为passthrough 属性:
<html ... xmlns:a="http://xmlns.jcp.org/jsf/passthrough"> ... <h:inputText ... a:autocorrect="off" />
(请注意,我使用
xmlns:a
而不是xmlns:p
为了避免与 PrimeFaces 默认命名空间发生冲突)或者:
<html ... xmlns:f="http://xmlns.jcp.org/jsf/core"> ... <h:inputText ...> <f:passThroughAttribute name="autocorrect" value="off" /> </h:inputText>
创建自定义渲染器。您可以在以下答案中找到几个具体示例: