KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > valid > IValidator


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.valid;
16
17 import org.apache.tapestry.IMarkupWriter;
18 import org.apache.tapestry.IRequestCycle;
19 import org.apache.tapestry.form.IFormComponent;
20
21 /**
22  * An object that works with an {@link IFormComponent} to format output (convert object values to
23  * strings values) and to process input (convert strings to object values and validate them).
24  * <p>
25  * Note that this interface represents validation as supported in Tapestry 2.x to 3.0. It has been
26  * outdated (and will eventually be deprecated) by new support in Tapestry 4.0, centered around the
27  * {@link org.apache.tapestry.form.translator.Translator} and
28  * {@link org.apache.tapestry.form.validator.Validator} interfaces.
29  *
30  * @author Howard Lewis Ship
31  * @since 1.0.8
32  */

33
34 public interface IValidator
35 {
36     /**
37      * All validators must implement a required property. If true, the client must supply a non-null
38      * value.
39      */

40
41     public boolean isRequired();
42
43     /**
44      * Invoked during rendering to convert an object value (which may be null) to a String. It is
45      * acceptible to return null. The string will be the VALUE attribute of the HTML text field.
46      */

47
48     public String JavaDoc toString(IFormComponent field, Object JavaDoc value);
49
50     /**
51      * Converts input, submitted by the client, into an object value. May return null if the input
52      * is null (and the required flag is false).
53      * <p>
54      * The input string will already have been trimmed. It may be null.
55      *
56      * @throws ValidatorException
57      * if the string cannot be converted into an object, or the object is not valid (due
58      * to other constraints).
59      */

60
61     public Object JavaDoc toObject(IFormComponent field, String JavaDoc input) throws ValidatorException;
62
63     /**
64      * Invoked by the field after it finishes rendering its tag (but before the tag is closed) to
65      * allow the validator to provide a contribution to the rendering process. Validators typically
66      * generated client-side JavaScript to peform validation.
67      *
68      * @since 2.2
69      */

70
71     public void renderValidatorContribution(IFormComponent field, IMarkupWriter writer,
72             IRequestCycle cycle);
73
74 }
Popular Tags