I thought everything that was not JSF was passed to the browswer for rendering?
This assumption is thus wrong. Unspecified component attributes are ignored by the JSF renderers.
You have basically the following options to get it to work:
-
If you’re already on JSF 2.2 or newer, set it as a passthrough attribute.
<... xmlns:a="http://xmlns.jcp.org/jsf/passthrough"> <h:inputText a:placeholder="fill me" />Note that I use a XML namespace prefix of
a(“attribute”) instead ofpas shown in the tutorial, as it would otherwise clash with default XML namespace prefixpof PrimeFaces. -
Implement a custom renderer for
<h:inputText>wherein you explicitly check and write the attribute. -
Implement a custom component which uses the aforementioned custom renderer.
-
Implement a JS based solution wherein you grab the element from DOM and explicitly set the attribute.
-
Look for a component library which supports this out the box. PrimeFaces for example has a
<p:watermark>for this purpose with nice JS based graceful degradation for browsers which does not support theplaceholderattribute on inputs.
See also:
- Custom HTML tag attributes are not rendered by JSF