Custom HTML tag attributes are not rendered by JSF

∥☆過路亽.° 提交于 2019-11-26 00:55:37

问题


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.

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

回答1:


This is by design. You can only specify attributes which are supported by 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.

There are several ways to solve this:

  1. 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 of xmlns: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>
    

  2. Use OmniFaces Html5RenderKit. Since the 1.5 release, it supports specifying custom attributes by <context-param>. See also the showcase example or Javadoc.


  3. Create a custom renderer. You can find several concrete examples in below answers:

    • How to let JSF pass through HTML attributes
    • Using bootstrap related tags inside JSF2 h:inputText component
    • How to render a custom attribute of <h:outputLink>?
    • InputText PrimeFace not applying maxlength
    • Adding Custom Attributes to Primefaces Autocomplete Component in JSF


来源:https://stackoverflow.com/questions/16666472/custom-html-tag-attributes-are-not-rendered-by-jsf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!