Search code examples
htmljsfjsf-2html-input

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


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

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

How can I achieve this?


Solution

  • 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.