2013-05-21 74 views
24

我想为我的登录表单添加一些iOS特定标记属性。如果我看看我的网页源代码,autocorrect,autocapitalize和拼写检查的属性就不存在了。这是什么原因?我正在使用JSF 2.x.JSF不呈现自定义HTML标记属性

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

回答

51

这是设计。您只能由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. 使用OmniFacesHtml5RenderKit。自1.5版本以来,它支持通过<context-param>指定自定义属性。另请参阅showcase exampleJavadoc


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

+0

感谢BalusC - 你是伟大的! – Jochen

+1

非常感谢BalusC,你是JSF的主人:)我几乎所有需要的都是由你来回答的。 – Simego

+0

这对我很有用,只要我用'http://xmlns.jcp.org/jsf/passthrough而不是旧的java.sun.com命名空间。 – Joost