JavaWeb with xhtml

2

How can I make a menu to enter the date of birth to register a new registration?

My code looks like this:

    <!-- Nome -->
    <h:outputText value="Nome" />
    <h:inputText value="#{CadastroDados.nome}" />
    <br />

    <!-- Sobrenome -->
    <h:outputText value="Sobrenome" />
    <h:inputText value="#{CadastroDados.sobrenome}" />
    <br />      

    <!--  Sexo -->
    <h:selectOneRadio id="selectsexo" value="#{CadastroDados.sexo}">
        <l:selectItem id="item1" itemLabel="Masculino" itemValue="Masculino" />
        <l:selectItem id="item2" itemLabel="Feminino" itemValue="Feminino" />
    </h:selectOneRadio>
    <br />      

    <!-- Data de Nascimento --> 
            <!-- ... -->

    <!-- Execução -->
    <h:commandButton value="Verificar" action="#{CadastroDados.exe}" />
    
asked by anonymous 12.05.2014 / 23:36

1 answer

4

With pure JSF you can use:

<h:inputText value="#{cadastroDados.dataNascimento}">  
   <f:convertDateTime pattern="dd/MM/yyyy"/>  
</h:inputText>

pattern is the expected date pattern on the entry. It follows the DateFormatter pattern. If you use ISO standard, for example, it would be yyyy-MM-dd . A common% share input component will be rendered.

If you can use a widget library such as PrimeFaces , you can use the calendar which is much simpler and makes a calendar appear on the page.

<p:calendar value="#{cadastroDados.dataNascimento}" />

(You will need to include PrimeFaces in your project and declare the <input> (or other) prefix with the library namespace.)

There is also the option to use HTML5 if you are using JSF 2.2. You will need to register a prefix for the resource namespace called "pass-through" ( p in the example below) and prefix HTML5 attributes in your input field. This way you can use HTML5 calendar rendering supported by the browser and capture your input data:

<h:inputText value="#{cadastroDados.dataNascimento}" pt:type="date" />

See 8.9 HTML5-Friendly Markup

Finally, there is a seamless way to use these features by including another library, OmniFaces . See an example in Adding HTML5 attributes to standard JSF components .

    
12.05.2014 / 23:50