background image

JavaBeans Components

<< The checkoutForm Page | The RetailPriceList JavaBeans Component >>
<< The checkoutForm Page | The RetailPriceList JavaBeans Component >>

JavaBeans Components

<h:inputText id=
"firstName" value="#{checkoutFormBean.firstName}"
size=
"15" maxlength="20" required="true"/>
With the required attribute set to true, the JavaServer Faces implementation will check
whether the user entered something in the First Name field.
The email component has a custom validator registered on it. Here is the tag corresponding to
the email component:
<h:inputText id=
"email" value="#{checkoutFormBean.email}"
size=
"25" maxlength="125" validator="#{checkoutFormBean.validateEmail}"/>
The validator attribute refers to the validateEmail method on the CheckoutFormBean class.
This method ensures that the value the user enters in the email field contains an @ character.
If the validation does not succeed, the checkoutForm is re-rendered, with error notifications in
each invalid field. If the validation succeeds, checkoutFormBean submits suborders to each
supplier and stores the result in the request-scoped OrderConfirmations JavaBeans
component and control is passed to the checkoutAck page.
The checkoutAck Page
checkoutAck
simply displays the contents of the OrderConfirmations JavaBeans component,
which is a list of the suborders constituting an order and the ship dates of each suborder. This
page also uses a UIData component. Again, the number of coffees the customer ordered is not
known before runtime. The UIData component dynamically adds rows to accommodate the
order.
The checkoutAck.jsp page also makes use of a custom converter that converts the shipping
date into an XMLGregorianCalendar type:
<h:outputText id=
"coffeeName"
value=
"#{oc.confirmationBean.shippingDate}">
<f:converter converterId=
"XMLGregorianCalendarConverter" /
</h:outputText>
The custom converter is implemented by XMLGregorianCalendarConverter.java.
JavaBeans Components
The JavaBeans components are as follows:
"The RetailPriceList JavaBeans Component" on page 1049
"The ShoppingCart JavaBeans Component" on page 1049
"The OrderConfirmations JavaBeans Component" on page 1049
"The CheckoutFormBean JavaBeans Component" on page 1049
Coffee Break Server
The Java EE 5 Tutorial · September 2007
1048