Your First Cup: An Introduction to the Java EE Platform

ProcedureAdding the Form to response.html

Add a form that displays the age difference between Duke and the user, displays the average age difference of all users, and allows the user to navigate back to greeting.xhtml.

  1. In the firstcup project in response.xhtml add the following tags between the <body> and </body> tags.

    <h:form>
        <h:outputText value="#{bundle.YouAre} "/>
        <h:outputText value="#{bundle.SameAge}"
                      rendered="#{DukesBDay.ageDiff == 0}"/>
        <h:outputText value="#{DukesBDay.absAgeDiff}"
                      rendered="#{DukesBDay.ageDiff lt 0}"/>
        <h:outputText value=" #{bundle.Year} "
                      rendered="#{DukesBDay.ageDiff == -1}"/>
        <h:outputText value=" #{bundle.Years} "
                      rendered="#{DukesBDay.ageDiff lt -1}"/>
        <h:outputText value="#{bundle.Younger}"
                      rendered="#{DukesBDay.ageDiff lt 0}"/>
        <h:outputText value="#{DukesBDay.absAgeDiff}"
                      rendered="#{DukesBDay.ageDiff gt 0}"/>
        <h:outputText value=" #{bundle.Year} "
                      rendered="#{DukesBDay.ageDiff == 1}"/>
        <h:outputText value=" #{bundle.Years} "
                      rendered="#{DukesBDay.ageDiff gt 1}"/>
        <h:outputText value="#{bundle.Older}" rendered="#{DukesBDay.ageDiff gt 0}"/>
        <p/>
        <h:outputText value="#{bundle.AverageAge}": #{DukesBday.averageAgeDifference}" />
        <p/>
        <h:commandButton id="back" value="#{bundle.Back}" action="greeting"/>
    </h:form>
  2. Right-click in the editor window and select Format.

  3. Select File -> Save.