KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > form > validator > Validator


1 // Copyright 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.form.validator;
16
17 import org.apache.tapestry.form.IFormComponent;
18 import org.apache.tapestry.form.FormComponentContributor;
19 import org.apache.tapestry.form.ValidationMessages;
20 import org.apache.tapestry.valid.ValidatorException;
21
22 /**
23  * An object that can be "attached" to a {@link org.apache.tapestry.form.IFormComponent} to perform
24  * server-side validation ({@link #validate(IFormComponent, ValidationMessages, Object)}) as well
25  * as generate cleint-side validation (in the form of JavaScript submit listeners).
26  *
27  * @author Paul Ferraro
28  * @since 4.0
29  */

30 public interface Validator extends FormComponentContributor
31 {
32     /**
33      * Invoked to validate input for the field. A
34      * {@link org.apache.tapestry.form.translator.Translator} will have already converted the
35      * submitted user input string into an object.
36      *
37      * @param field
38      * the form element component being validated, often used to determine the
39      * {@link IFormComponent#getDisplayName() user presentable name} for the field, used
40      * in error messages.
41      * @param messages
42      * access to the pre-defined validation messages, in the appropriate locale
43      * @param object
44      * the client-side representation of the field's data. May be null if the client did
45      * not provide a value for the field (most Validators should check for null and
46      * perform no check if null).
47      * @throws ValidatorException
48      * if the object violates the constraint represented by this Validator.
49      */

50
51     public void validate(IFormComponent field, ValidationMessages messages, Object JavaDoc object)
52             throws ValidatorException;
53     
54     /**
55      * Returns true if this validator accepts null as the object parameter to validate(). When the object
56      * is null, validators that can't accept null are skipped. It is rare for a validator to return true.
57      *
58      */

59     
60     public boolean getAcceptsNull();
61 }
62
Popular Tags