Welcome.jsp
[Previous] [Main] [Next]

Welcome.jsp


Here is the annotated code for the Welcome.jsp file.

<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<f:view>
<head>
<title>Adding Power - JavaServer Faces Application</title>
</head>
<body>
<h:form>
<h3>
Welcome to JavaServer Faces,
<h:outputText value="#{user.name}"/>!
<-- bean data
</h3>
<p>
I see you are using the following browser:<br>
<h:outputText value = "#{header['User-Agent']}"/>
<--Note: the HTTP Request header information is all available to you.
<p>
<strong>
<h:outputText value="Update Personal Information"/>
</strong>
<p>
<h:outputLabel for="city">
<-- We could just output text, but this gives us Accessibility (A11y)
<h:outputText value="City: " />
</h:outputLabel>
<h:inputText id="city" value= "#{user.city}" required="true"/>
<-- required="true" make a component invalid if it is empty
<br>
<h:outputLabel for="zip"/>
<h:outputText value="Zip: "/>
</h:outputLabel>
<h:inputText id="zip" value= "#{user.zip}">
<f:validateLength minimum="5" maximum="9"/>
<-- One of JSF's default validators
</h:inputText>
<br>
<h:outputLabel for="yearjava">
<h:outputText value="Years using Java: "/>
</h:outputLabel>
<h:inputText id="yearjava" value= "#{user.javaYear}"/>
<-- the yearJava property is an integer. JSF automatically converts the string to an integer and validates that the data is numeric.
<br>
<h:outputLabel for="dob">
<h:outputText value="Date of Birth: "/>
</h:outputLabel>
<h:inputText id="dob" value= "#{user.dob}">
<f:convertDateTime pattern="MM/dd/yyyy"/>
<-- Another default converter.
</h:inputText>
<br>
<h:messages/>
<-- Here is the command that tell JSF where to put the error messages.
<h:commandButton value="Continue" action="#{user.more}"/>
<-- A method bound to an action. This uses the JSF default listener.
<h:commandButton value="Login" immediate="true" action="login"/>
<-- "immediate="true" bypasses the validations and goes right to the navigation section.
<h:commandButton value="Help" action="help"/>
<-- This is a direct action. Instead of a method returning a string, the action itself is the string used for navigation. ALSO NOTE: This command has an error. Without the "immediate='true'" flag, a user cannot get to the HELP screen without filling in all of the data correctly. See the Life Cycle screens.
</h:form>
</body>
</f:view>
</html>