Home arrow Java & J2EE arrow Page 6 - Introduction to JavaServer Faces Part 2

Authoring the JSP Page for the Validator Example - Java

We continue with part two of Chapter 2 of Introduction JavaServer Faces Programming, by Budi Kurniawan (McGraw-Hill/Osborne, ISBN 0-07-222983-7, 2004). This section deals with the ActionListener and Component Tree, as well as validation and navigation for your JSP pages.  This chapter prepares you for the next chapters by introducing the JSF Application Programming Interface (API) and the Application Configuration file.

  1. Introduction to JavaServer Faces Part 2
  2. The Action Listener
  3. Continuing With the navigateComponent Tree
  4. Console Message
  5. And the Message
  6. Authoring the JSP Page for the Validator Example
By: McGraw-Hill/Osborne
Rating: starstarstarstarstar / 23
March 15, 2004

print this article



The JSP page is the only component in this application. It is called validatorTest.jsp and is shown in Listing 6.

Listing 6 The validatorTest.jsp Page

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<title>Validator Test</title>
<h:form formName="myForm">
Enter a minimum of 6 characters here
<f:validate_length minimum="6"/>
<h:command_button label="Submit" commandName="submit"/>

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>The validatorTest.jsp page contains a form with a UIInput component represented by the input_text custom tag. The form also contains a command_button tag representing a UICommand, as well as an output_errors tag for displaying any error that occurs during processing. The most important part is the validate_length tag inside the input_text tag.

<f:validate_length minimum="6"/>

JSF Validator

Figure 8 The directory structure for the validator example 

The validate_length tag represents one of the standard validators in JSF. It checks for the length of the input and makes sure that it has a minimum of six characters. Any input shorter than six characters will generate an error that will be displayed by the output_errors tag.

Running the Validator Example

To run the application, you need to restart Tomcat. Then, use the following URL to invoke the validatorTest.jsp page:


Figure 9 shows the error message displayed for an input value shorter than six characters. 

JSF validator

Figure 9 The validator example in action

Buy this book now!Remember: This is part two of the second chapter of JavaServer Faces Programming, by Budi Kurniawan (McGraw-Hill/Osborne, ISBN 0-07-222983). Stay tuned for more helpful chapters from McGraw-Hill/Osborne.
Buy this book!

>>> More Java & J2EE Articles          >>> More By McGraw-Hill/Osborne

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates


Dev Shed Tutorial Topics: