001 // Copyright 2008 The Apache Software Foundation002 //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 at006 //007 // http://www.apache.org/licenses/LICENSE-2.0008 //009 // Unless required by applicable law or agreed to in writing, software010 // 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 and013 // limitations under the License.014015 package org.apache.tapestry5;016017 /**018 * A wrapper around {@link org.apache.tapestry5.Translator} that combines the translator for a specific {@link019 * org.apache.tapestry5.Field} and (sometimes) an override of the default validation message (used when an input value020 * can't be parsed).021 */022 public interface FieldTranslator<T>023 {024 /**025 * Returns the type of the server-side value.026 *027 * @return a type028 */029 Class<T> getType();030031 /**032 * Invoked after the client-submitted value has been {@link Translator translated} to check that the value conforms033 * to expectations (often, in terms of minimum or maximum value). If and only if the value is approved by all034 * Validators is the value applied by the field.035 *036 * @throws ValidationException if the value violates the constraint037 */038 T parse(String input) throws ValidationException;039040 /**041 * Converts a server-side value to a client-side string. This allows for formatting of the value in a way042 * appropriate to the end user.043 *044 * @param value the server side value (which will not be null)045 * @return client-side value to present to the user046 * @see Translator#toClient(Object)047 */048 String toClient(T value);049050 /**051 * Invokes {@link Translator#render(Field, String, MarkupWriter,org.apache.tapestry5.services.FormSupport)}. This is052 * called at a point "inside" the tag, so that additional attributes may be added. In many cases, the underlying053 * {@link org.apache.tapestry5.Validator} may write client-side JavaScript to enforce the constraint as well.054 *055 * @param writer markup writer to direct output to.056 * @see org.apache.tapestry5.MarkupWriter#attributes(Object[])057 */058 void render(MarkupWriter writer);059 }