• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Custom validator problem

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post your validator tag code?
 
Krzysztof Malik
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"
or
xmlns:started="urn:jsptld:/WEB-INF/started.tld"
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic