1

I'm having a problem with Java Server Faces... Actually, I don't know what to do.

The exercise is to make a BMI (Body Mass Index) app with Java Server Faces. You put your name, your birthdate (i.e: 10/03/2000, 19 years ago. BTW I use dd/MM/yyyy), weight (kg) and height (cm).

Click to calculate your BMI and in the other page it shows your name, your age (that'd be 19 with the example) and your BMI. The problem that I'm having is that I don't know how to show in the page the age, only the date that I put in the first place (Day of the week in that year, March, 2000).

Can someone help me, please ? I'm still learning. Do I need to create a converter Age class ? Some function might help me ?

P.S: The variables are in portuguese, so: Nome = Name, Data de Nascimento = BirthDate, Peso = Weight, Altura = Height, Idade = Age, IMC = BMI, Dados = Data, dadosIMC = BMIData

Thanks for reading, the xhtml code is below.

<h:body> <!--INDEX-->
        <h:form>
            <h:panelGrid columns="2">
                <h:outputLabel value="Nome:" for="nome"/>  
                <h:inputText value="#{dadosIMC.dados.nome}" id="nome"
                             label="nome"/>                                     
                <h:outputLabel value="Data de Nascimento:" for="nascimento"/>
                <h:inputText value="#{dadosIMC.dados.nascimento}" id="nascimento"
                             label="data de nascimento"
                             validatorMessage="#{msgs.erroNascimento}">
                    <f:convertDateTime type="date" pattern="dd/MM/yyyy" />
                </h:inputText>
                <h:outputLabel value="Peso (KG):" for="peso"/>
                <h:inputText value="#{dadosIMC.dados.peso}" id="peso"
                             label="peso"/>
                <h:outputLabel value="Altura (CM):" for="altura"/>
                <h:inputText value="#{dadosIMC.dados.altura}" id="altura"
                             label="altura"/>
            </h:panelGrid>
            <h:commandButton value="Calcular" action="#{dadosIMC.dados.calculaIMC()}"/>
        </h:form>
    </h:body>
    
    <h:body> <!--RESULT PAGE-->
        <h:panelGrid columns="2">
            Nome:
            <h:outputText value="#{dadosIMC.dados.nome}"/>
            Idade:
            <h:outputText value="don't know what to put"/>
            IMC:
            <h:outputText value="#{dadosIMC.dados.resultado}"/>
        </h:panelGrid>
        <h:button value="Voltar" outcome="/index"/>
    </h:body>
Kukeltje
  • 11,924
  • 4
  • 19
  • 44
Marrows
  • 73
  • 1
  • 6
  • And read https://stackoverflow.com/questions/30639785/jsf-controller-service-and-dao (which is sort of not even jsf specific. The same holds for any ui framework or rest or ... – Kukeltje Mar 11 '19 at 07:19
  • And please read [tagging](https://stackoverflow.com/help/tagging) about the tags you use. – Kukeltje Mar 11 '19 at 09:30
  • And you can do this in jsf 'converter' if that is what your professor wants ypu to find out – Kukeltje Mar 11 '19 at 09:47
  • I don't know if it's a duplicate or not, but I'm sorry if it is. I searched for this question with JSF in mind, not just Java. – Marrows Mar 11 '19 at 17:48
  • And I'm sorry about tagging too, there's no tag for java server faces in stack – Marrows Mar 11 '19 at 17:49

0 Answers0