Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to bind value of a HTML5 <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?

like image 797
Pigritia Avatar asked Nov 21 '12 00:11

Pigritia


2 Answers

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.

like image 104
BalusC Avatar answered Nov 12 '22 13:11

BalusC


Another way (works only with JSF 2.2) is to use the f:passThroughAttribute inside your inputText:

<h:inputText id="yourNumberField" value="#{mainController.myBeautifulNumber}">
    <f:passThroughAttribute name="type" value="number"/>
    <f:passThroughAttribute name="step" value="0.02"/>
</h:inputText>

The f: namespace is the default xmlns:f="http://xmlns.jcp.org/jsf/core".

like image 26
Mateus Viccari Avatar answered Nov 12 '22 12:11

Mateus Viccari