【问题标题】:Custom HTML tag attributes are not rendered by JSFJSF 不呈现自定义 HTML 标记属性
【发布时间】:2013-05-16 00:16:55
【问题描述】:

我想在我的登录表单中添加一些 iOS 特定的标签属性。如果我查看我的网页源代码,则不存在自动更正、自动大写和拼写检查的属性。这是什么原因?我正在使用 JSF 2.x。

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

【问题讨论】:

    标签: html jsf custom-attributes renderer


    【解决方案1】:

    这是设计使然。您只能通过 JSF 组件本身指定 supported 的属性(即它在 tag documentation 的属性列表中列出)。您不能指定任意附加属性,它们都将被完全忽略。

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

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

      <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>
      

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

    【讨论】:

    • 这对我有用,只要我使用 http://xmlns.jcp.org/jsf/passthrough 而不是旧的 java.sun.com 命名空间。
    • @Joost:这是旧 Mojarra 版本中的错误。但你是对的,我应该提倡新的命名空间。答案已更新。
    • 你知道他们为什么这样设计吗?
    • @BalusC Html5RenderKit 自 OmniFaces 2 以来已被弃用。这是指向展示柜的链接不再有效的原因吗?大概可以换成omnifaces.org/docs/javadoc/2.5/org/omnifaces/renderkit/…
    • @BalusC 嗨,由于某些原因,我们坚持使用 Jsf 2.0,我相信它不支持 passThroughAttributes。有没有办法在 jsf 2.0 中拥有 html5 属性?
    猜你喜欢
    • 2012-01-26
    • 1970-01-01
    • 2015-01-20
    • 2015-03-29
    • 2012-04-05
    • 2011-01-13
    相关资源
    最近更新 更多