background image

Writing the Tag Library Descriptor

<< Creating a Custom Tag | Writing Backing Bean Methods >>
<< Creating a Custom Tag | Writing Backing Bean Methods >>

Writing the Tag Library Descriptor

protected ValueExpression formatPatterns = null;
public void setFormatPatterns(ValueExpression fmtPatterns){
formatPatterns = fmtPatterns;
}
Finally, the createValidator method creates an instance of FormatValidator, extracts the
value from the formatPatterns attribute's value expression and sets the formatPatterns
property of FormatValidator to this value:
the formatPatterns property of FormatValidator to this value:
protected Validator createValidator() throws JspException {
FacesContext facesContext =
FacesContext.getCurrentInstance();
FormatValidator result = null;
if(validatorID != null){
result = (FormatValidator) facesContext.getApplication()
.createValidator(validatorID);
}
String patterns = null;
if (formatPatterns != null) {
if (!formatPatterns.isLiteralText()) {
patterns = (String)
formatPatterns.getValue(facesContext.getELContext());
} else {
patterns = formatPatterns.getExpressionString();
}
Writing the Tag Library Descriptor
To define a tag, you declare it in a tag library descriptor (TLD), which is an XML document that
describes a tag library. A TLD contains information about a library and each tag contained in it.
See
"Tag Library Descriptors" on page 247
for more information about TLDs.
The custom validator tag is defined in bookstore.tld, located in the
tut-install/javaeetutorial5/examples/web/bookstore6/web/WEB-INF/ directory. It
contains a tag definition for formatValidator:
<tag>
<name>formatValidator</name>
...
<tag-class>
com.sun.bookstore6.taglib.FormatValidatorTag</tag-class>
<attribute>
<name>formatPatterns</name>
<required>true</required>
<deferred-value>
Creating a Custom Validator
Chapter 12 · Developing with JavaServer Faces Technology
403