29

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

73

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. Create a custom renderer. You can find several concrete examples in below answers:

8
  • This works for me, as long as i use http://xmlns.jcp.org/jsf/passthrough rather than the old java.sun.com namespace.
    – Joost
    Mar 18, 2015 at 8:13
  • @Joost: This is a bug in older Mojarra versions. But you're right, I should be advocating the new namespace instead. Answer has been updated.
    – BalusC
    Mar 18, 2015 at 8:28
  • 2
    Do you know why they designed it this way ?
    – Ced
    Apr 14, 2016 at 16:47
  • @BalusC the Html5RenderKit is deprecated since OmniFaces 2. Is that the reason the link to the showcase is no longer working? It can probably be replaced with omnifaces.org/docs/javadoc/2.5/org/omnifaces/renderkit/… Oct 10, 2016 at 12:23
  • @BalusC Hi, We are stuck with Jsf 2.0 for some reasons and I believei it does not support passThroughAttributes. Is there a way to have html5 attributes in jsf 2.0?
    – Nikhil
    Nov 15, 2016 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.