O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the Standard Validators

The expense report entry form part of the sample application contains a number of fields that require validation: all fields must have a value, a syntactically valid date must be entered in the Date field, and the Amount field must contain an amount larger than one. Figure 7-1 shows all these fields, with a couple of error messages, generated by the initial implementation of this form.

The first version of the report entry form area JSP page

Figure 7-1. The first version of the report entry form area JSP page

The JSP file for this version of the form is shown in Example 7-2.

Example 7-2. Initial report entry form area JSP page (expense/stage1/entryFormArea.jsp)

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

<f:view>
  <h:form>
    Title: 
    <h:inputText id="title" size="30" required="true"
      value="#{reportHandler.currentReport.title}" />
    <h:message for="title" />
    <br>
    Entry:
    <br>
    Date: 
    <h:inputText id="date" size="8" required="true"
      value="#{entryHandler.currentEntry.date}">
      <f:convertDateTime dateStyle="short" />
    </h:input_text>
    <h:message for="date" />
    <br>
    Type:
    <h:selectOneMenu id="type" required="true"
      value="#{entryHandler.currentEntry.type}">
      <f:selectItems value="#{entryHandler.expenseTypeChoices}"/>
    </h:selectOneMenu>
    <h:message for="type" />
    <br>
    Amount:
    <h:inputText id="amount" size="8" required="true" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required