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 JSP file for this version of the form is shown in Example 7-2.
<%@ 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:inputTextid="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:inputTextid="amount"
size="8"required="true" ...
Get JavaServer Faces now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.