001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.valid; 016 017 import org.apache.tapestry.IMarkupWriter; 018 import org.apache.tapestry.IRequestCycle; 019 import org.apache.tapestry.engine.IScriptSource; 020 import org.apache.tapestry.form.IFormComponent; 021 022 /** 023 * An object that works with an {@link IFormComponent} to format output (convert object values to 024 * strings values) and to process input (convert strings to object values and validate them). 025 * <p> 026 * Note that this interface represents validation as supported in Tapestry 2.x to 3.0. It has been 027 * outdated (and will eventually be deprecated) by new support in Tapestry 4.0, centered around the 028 * {@link org.apache.tapestry.form.translator.Translator} and 029 * {@link org.apache.tapestry.form.validator.Validator} interfaces. 030 * 031 * @author Howard Lewis Ship 032 * @since 1.0.8 033 */ 034 035 public interface IValidator 036 { 037 /** 038 * All validators must implement a required property. If true, the client must supply a non-null 039 * value. 040 */ 041 042 boolean isRequired(); 043 044 /** 045 * Invoked during rendering to convert an object value (which may be null) to a String. It is 046 * acceptible to return null. The string will be the VALUE attribute of the HTML text field. 047 */ 048 049 String toString(IFormComponent field, Object value); 050 051 /** 052 * Converts input, submitted by the client, into an object value. May return null if the input 053 * is null (and the required flag is false). 054 * <p> 055 * The input string will already have been trimmed. It may be null. 056 * 057 * @throws ValidatorException 058 * if the string cannot be converted into an object, or the object is not valid (due 059 * to other constraints). 060 */ 061 062 Object toObject(IFormComponent field, String input) throws ValidatorException; 063 064 /** 065 * Invoked by the field after it finishes rendering its tag (but before the tag is closed) to 066 * allow the validator to provide a contribution to the rendering process. Validators typically 067 * generated client-side JavaScript to peform validation. 068 * 069 * @since 2.2 070 */ 071 072 void renderValidatorContribution(IFormComponent field, IMarkupWriter writer, 073 IRequestCycle cycle); 074 075 /** 076 * Sets the script source used to resolve script paths. 077 * 078 * @param scriptSource 079 */ 080 void setScriptSource(IScriptSource scriptSource); 081 }