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 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 ...

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