JSF不呈现自定义HTML标记属性

Joc*_*hen 27 html jsf renderer custom-attributes

我想在登录表单中添加一些iOS特定的标记属性.如果我查看我的网页源代码,那么属性autocorrect,autocapitalize和spellcheck就不存在了.这是什么原因?我正在使用JSF 2.x.

<h:inputText id="user-name" forceId="true" value="#{login.username}" style="width:120px;"
    autocorrect="off" autocapitalize="off" spellcheck="false" />
Run Code Online (Sandbox Code Playgroud)

Bal*_*usC 60

这是设计的.您只能指定JSF组件本身支持的属性(即它在标记文档的属性列表中列出).您不能指定任意附加属性,它们都将被忽略.

有几种方法可以解决这个问题:

  1. 如果您已经使用JSF 2.2+,只需将其指定为passthrough属性:

    <html ... xmlns:a="http://xmlns.jcp.org/jsf/passthrough">
    ...
    <h:inputText ... a:autocorrect="off" />
    
    Run Code Online (Sandbox Code Playgroud)

    (注意我正在使用xmlns:a而不是xmlns:p为了避免与PrimeFaces默认命名空间发生冲突)

    要么:

    <html ... xmlns:f="http://xmlns.jcp.org/jsf/core">
    ...
    <h:inputText ...>
        <f:passThroughAttribute name="autocorrect" value="off" />
    </h:inputText>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 使用OmniFaces Html5RenderKit.从1.5版本开始,它支持通过指定自定义属性<context-param>.另请参见showcase示例Javadoc.


  3. 创建自定义渲染器.您可以在以下答案中找到几个具体示例:

  • 你知道他们为什么这样设计吗? (2认同)