001 // Copyright 2006, 2007, 2008 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.tapestry5; 016 017 /** 018 * Responsible for validation of a single field. 019 * 020 * @param <T> 021 * @see Validator 022 * @see org.apache.tapestry5.services.FieldValidatorDefaultSource 023 */ 024 public interface FieldValidator<T> 025 { 026 /** 027 * Invoked after the client-submitted value has been {@link Translator translated} to check that the value conforms 028 * to expectations (often, in terms of minimum or maximum value). If and only if the value is approved by all 029 * Validators is the value applied by the field. 030 * 031 * @param value the translated value supplied by the user 032 * @throws ValidationException if the value violates the constraint 033 */ 034 void validate(T value) throws ValidationException; 035 036 /** 037 * Invokes {@link Validator#render(Field, Object, org.apache.tapestry5.ioc.MessageFormatter, MarkupWriter, 038 * org.apache.tapestry5.services.FormSupport)}. This is called at a point "inside" the tag, so that additional 039 * attributes may be added. In many cases, the underlying {@link org.apache.tapestry5.Validator} may write 040 * client-side JavaScript to enforce the constraint as well. 041 * 042 * @param writer markup writer to direct output to. 043 * @see org.apache.tapestry5.MarkupWriter#attributes(Object[]) 044 */ 045 void render(MarkupWriter writer); 046 047 /** 048 * Returns true if any underlying {@link org.apache.tapestry5.Validator} returns true from {@link 049 * org.apache.tapestry5.Validator#isRequired()}. 050 * 051 * @return true if the field is required (a non-blank value is expected) 052 */ 053 boolean isRequired(); 054 }