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" />
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Jochen
  • 1,746
  • 4
  • 22
  • 48

1 Answers1

74

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:

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 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 '15 at 08: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 '15 at 08:28
  • 2
    Do you know why they designed it this way ? – Ced Apr 14 '16 at 16:47
  • @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 '16 at 18:40
  • @Nikhil: That's covered by ways 2 and 3 in the answer. – BalusC Nov 16 '16 at 07:03
  • Just thought I would add that works inside of tags too. Perhaps that is a given to most people but it was not for me. –  Aug 01 '18 at 16:41
  • With all due respect to @BalusC as a great developer and participant on this site... I think devs need to take a much harder look at using JSF (ever). After multiple projects, all of my teams and myself included despised it for all of the problems caused for whatever problems it solved. In the end we found over multiple projects that it was much less error-prone, flexible, performant to separate model on server (using JSON schema et al) from the presentation layer technology (Angular et al). – Darrell Teague May 29 '20 at 18:03