我想在我的登录表单中添加一些特定于 iOS 的标签属性。如果我查看网页源代码,会发现自动更正、自动大写和拼写检查属性不存在。这是什么原因?我正在使用 JSF 2.x。
<h:inputText id="user-name" forceId="true" value="#{login.username}" style="width:120px;"
autocorrect="off" autocapitalize="off" spellcheck="false" />
最佳答案
这是设计使然。您只能指定 supported 的属性由 JSF 组件本身(即它列在 tag documentation 的属性列表中)。您不能指定任意的附加属性,它们都将被忽略。
有几种方法可以解决这个问题:
如果您已经在使用 JSF 2.2+,只需将其指定为 passthrough attribute :
<html ... xmlns:a="http://xmlns.jcp.org/jsf/passthrough"> ... <h:inputText ... a:autocorrect="off" />
(请注意,我使用
xmlns:a
而不是xmlns:p
以避免与 PrimeFaces 默认 namespace 发生冲突)或者:
<html ... xmlns:f="http://xmlns.jcp.org/jsf/core"> ... <h:inputText ...> <f:passThroughAttribute name="autocorrect" value="off" /> </h:inputText>
创建自定义渲染器。您可以在以下答案中找到几个具体示例:
关于html - JSF 不呈现自定义 HTML 标记属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16666472/