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.
<%@ 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.
Figure 8The 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.
Figure 9The validator example in action
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!