The Java EE 5 Tutorial

The CheckoutFormBean JavaBeans Component

CheckoutFormBean checks the completeness of information entered into checkoutForm. If the information is incomplete, the bean populates error messages, and redisplays checkoutForm with the error messages. If the information is complete, order requests are constructed from the shopping cart and the information supplied to checkoutForm, and these orders are sent to each supplier. As each confirmation is received, an order confirmation is created and added to OrderConfirmations.

Several of the tags on the checkoutForm page have their required attributes set to true. This will cause the implementation to check whether the user enters values in these fields. The tag corresponding to the email component registers a custom validator on the email component, as explained in The checkoutForm Page. The code that performs the validation is the validateEmail method:

public void validateEmail(FacesContext context,
        UIComponent toValidate, Object value) {
    String message = "";
    String email = (String) value;
    if (email.indexOf(’@’) == -1) {
        message = CoffeeBreakBean.loadErrorMessage(context,
            CoffeeBreakBean.CB_RESOURCE_BUNDLE_NAME, "EMailError");
            new FacesMessage(message));