File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Custom validator problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Custom validator problem" Watch "Custom validator problem" New topic

Custom validator problem

Krzysztof Malik

Joined: Jul 24, 2007
Posts: 4
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

Validate an input string value against a series of format
patterns specified by the "formatPatterns" attribute.
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.

I've witten started.tld in WEB-INF/

<?xml version="1.0" encoding="UTF-8"?>

<taglib version="2.0" xmlns="" xmlns:xsi="" xsi:schemaLocation=" web-jsptaglibrary_2_0.xsd">



<!-- second version -->

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.



My test page (OwnValidator):

<?xml version="1.0" encoding="UTF-8"?>
<jsp:root version="1.2" xmlns:started="/WEB-INF/started.tld" xmlns:f="" xmlns:h=""
xmlns:jsp="" xmlns:webuijsf="">
< contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
<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: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:message for="textField1" styleClass="error-message"/>
<webuijsf:button binding="#{OwnValidator.button1}" id="button1" style="left: 71px; top: 96px; position: absolute" text="Button"/>

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?

Ryan Lubke
Ranch Hand

Joined: Jun 20, 2007
Posts: 36
Can you post your validator tag code?
Krzysztof Malik

Joined: Jul 24, 2007
Posts: 4
I've resolved problem. It's tricky for me but it has sense. Problem is in jsp page.
is: xmlns:started="/WEB-INF/started.tld"
should be: xmlns:started="/WEB-INF/started"
If I used the standard jsp, not xml, the original version (xmlns:started="/WEB-INF/started.tld") also would work.

Thanks Ryan for readiness for help.
I agree. Here's the link:
subject: Custom validator problem
It's not a secret anymore!