Is it possible to bind value of a HTML5 <input type="date"> to a JSF managed bean property?

Pigritia picture Pigritia · Nov 21, 2012 · Viewed 8.6k times · Source

I would like to use the new HTML5 <input type="date"> and bind its value to a managed bean:

<input type="date" value="#{bean.date}"/>

How can I achieve this?

Answer

BalusC picture BalusC · Nov 21, 2012

This is only possible since JSF 2.2. This feature is known as "passthrough elements".

<html xmlns:jsf="http://xmlns.jcp.org/jsf">
...
<input type="date" jsf:value="#{bean.date}" />

Alternatively, use "passthrough attributes".

<html xmlns:a="http://xmlns.jcp.org/jsf/passthrough">
...
<h:inputText a:type="date" value="#{bean.date}" />

In older JSF versions, use a custom component and/or renderer. You can find links to examples in Custom HTML tag attributes are not rendered by JSF.