Developing a Validator Custom Action

If you’re new to JSP, the concept of custom tag libraries and custom actions may seem like hocus pocus, so let’s take it step by step.

You’ve already seen the JSF and JSTL tag libraries in action. The only thing that differs between them and a custom tag library developed in-house or by a third party is that they are defined by public specifications. Other than that, they are just tag libraries, developed using the same JSP API that you use to develop your own custom tag libraries.

The behavior of a custom action is implemented by a Java class called a tag handler, and linked to a tag name and rules for how it can be used declared in a Tag Library Descriptor (TLD). Related custom actions are declared in the same TLD, together making up the library. Besides custom action declarations, the TLD also contains information about the library itself. Example 7-6 shows the TLD for the library with the <my:validateLater> action.

Example 7-6. The TLD for the example tag library (taglib.tld)
<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"> <taglib> <tlib-version>1.0</tlib-version> <jsp-version>1.2</jsp-version> <short-name>my</short-name> <uri>http://mycompany.com/jsftaglib</uri> <tag> <name>validateLater</name> <tag-class>com.mycompany.jsf.taglib.ValidateLaterThanTag</tag-class> <body-content>empty</body-content> <attribute> <name>than</name> ...

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.