Using a Custom Validator in a JSP Page

To use a custom validator in a JSP page, you need a JSP custom action that configures the converter and attaches it to a component. Example 7-5 shows the version of the filtering criteria form from the JSP page that produces the screen in Figure 7-2.

Example 7-5. The filtering criteria form with a custom validator (expense/stage4/filterArea.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" %>
<%@ taglib uri="http://mycompany.com/jsftaglib" prefix="my" %>

<f:view>
  <h:form>
    From: 
    <h:inputText id="from" size="8" required="true"
      value="#{reportHandler.from}">
      <f:convertDateTime dateStyle="short" />
    </h:inputText>
    <h:message for="from" />
    <br>
    To: 
    <h:inputText id="to" size="8" required="true"
      value="#{reportHandler.to}">
      <f:convertDateTime dateStyle="short" />
      <my:validateLater than="from" />
    </h:inputText>
    <h:message for="to" />
    <br>
    Status:
    <h:selectManyCheckbox value="#{reportHandler.status}">
      <f:selectItem itemValue="1" itemLabel="Open" />
      <f:selectItem itemValue="2" itemLabel="Submitted" />
      <f:selectItem itemValue="3" itemLabel="Accepted" />
      <f:selectItem itemValue="4" itemLabel="Rejected" />
    </h:selectManyCheckbox>
    <p>
    <h:commandButton value="Filter" />
  </h:form>
</f:view>

The custom action that configures the validator and attaches it to the component for the To field in Example 7-5 is called <my:validateLater> and belongs to the custom ...

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.