Javaweb with xhtml

Asked

Viewed 128 times

2

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

My code is 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}" />

1 answer

4


With pure JSF you can use:

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

The pattern is the expected date pattern in the input. Follows the pattern of the DateFormatter. If you use ISO standard, for example, it would be yyyy-MM-dd. An input component will be rendered <input> common.

If you can use a widgets library like the Primefaces, you can use the component 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 prefix p (or other) 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" (pt in the example below) and prefix the HTML5 attributes in your input field. So you can use the HTML5 calendar rendering supported by the browser and capture your input data:

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

Behold 8.9 HTML5-Friendly Markup

Finally, there is a transparent way to use these resources through the inclusion of another library, the Omnifaces. See an example in Adding HTML5 Attributes to standard JSF Components.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.