Hello,
I've written custom validator (according to The
Java EE 5 Tutorial Third Edition) and it don't work.
I've used tag handler from sample bookstore6: FormatValidatorTag
I've used validator class from sample bookstore6: FormatValidator
I've registered validator in faces-confi.xml
<validator>
<description>
Validate an input
string value against a series of format
patterns specified by the "formatPatterns" attribute.
</description>
<validator-id>FormatValidator</validator-id>
<validator-class>gettingstarted.FormatValidator</validator-class>
<attribute>
<description>
A list of format patterns separated by "|" characters.
Patterns are composed of "A" to require a letter, "9" to
require a digit, "#" to require either a number or a letter,
and other characters that must match exactly.
</description>
<attribute-name>formatPatterns</attribute-name>
<attribute-class>java.lang.String</attribute-class>
</attribute>
</validator>
I've witten started.tld in WEB-INF/
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
<tlib-version>1.0</tlib-version>
<short-name>started</short-name>
<uri>/WEB-INF/started</uri>
<!--jsp-version>1.2</jsp-version>
<short-name>started</short-name>
<uri>/WEB-INF/started</uri-->
<tag>
<name>formatValidator</name>
<tag-class>gettingstarted.FormatValidatorTag</tag-class>
<body-content>
JSP</body-content>
<attribute>
<name>formatPatterns</name>
<required>true</required>
<rtexprvalue>false</rtexprvalue>
<type>java.lang.String</type>
</attribute>
</tag>
<!-- second version -->
<!--tag>
<name>formatValidator</name>
<tag-class>gettingstarted.FormatValidatorTag</tag-class>
<body-content>JSP</body-content>
<description>
Defines the format-validator tag, with the
tag-handler class, carstore.FormatValidatorTag. This tag
must be nested inside a UI component tag. The value of the
UI component whose tag encloses the format_validator tag
is validated against the format patterns defined by the
formatPatterns attribute.
</description>
<attribute>
<name>formatPatterns</name>
<required>true</required>
<deferred-value>
<type>
java.lang.String
</type>
</deferred-value>
</attribute>
</tag-->
</taglib>
My
test page (OwnValidator):
<?xml version="1.0" encoding="UTF-8"?>
<jsp:root version="1.2" xmlns:started="/WEB-INF/started.tld" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:webuijsf="http://www.sun.com/webui/webuijsf">
<jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
<f:view>
<webuijsf:page binding="#{OwnValidator.page1}" id="page1">
<webuijsf:html binding="#{OwnValidator.html1}" id="html1">
<webuijsf:head binding="#{OwnValidator.head1}" id="head1">
<webuijsf:link binding="#{OwnValidator.link1}" id="link1" url="/resources/stylesheet.css"/>
</webuijsf:head>
<webuijsf:body binding="#{OwnValidator.body1}" id="body1" style="-rave-layout: grid">
<webuijsf:form binding="#{OwnValidator.form1}" id="form1">
<h:inputText binding="#{OwnValidator.textField1}" id="textField1" required="true" style="left: 72px; top: 48px; position: absolute">
<started:formatValidator formatPatterns="9999999999999999|9999 9999 9999 9999|9999-9999-9999-9999"/>
</h:inputText>
<h:message for="textField1" styleClass="error-message"/>
<webuijsf:button binding="#{OwnValidator.button1}" id="button1" style="left: 71px; top: 96px; position: absolute" text="Button"/>
</webuijsf:form>
</webuijsf:body>
</webuijsf:html>
</webuijsf:page>
</f:view>
</jsp:root>
I use NB 5.5+Visual Web, jdk 1.5, Sun Java System Application Server 9.
When I wrote incorrect value to inputText it was nothing happend.
When I wrote nothing the error message was appearing. On debug, the validate method in FormatValidator wasn't invoked.
What is wrong?
Thanks,
Chris.