001 // Copyright 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.form.translator;
016
017 import java.util.Locale;
018
019 import org.apache.tapestry.form.IFormComponent;
020 import org.apache.tapestry.form.FormComponentContributor;
021 import org.apache.tapestry.form.ValidationMessages;
022 import org.apache.tapestry.valid.ValidatorException;
023
024 /**
025 * Interface used by {@link ValidatableField}s to both format an object as text and translate
026 * submitted text into an appropriate object for a given field.
027 *
028 * @author Paul Ferraro
029 * @since 4.0
030 */
031 public interface Translator extends FormComponentContributor
032 {
033 /**
034 * Invoked during rendering to format an object (which may be null) into a text value (which
035 * should not be null) appropriate for the specified field.
036 * @param locale TODO
037 */
038 public String format(IFormComponent field, Locale locale, Object object);
039
040 /**
041 * Invoked during rewind to parse a submitted input value into an object suitable for the
042 * specified component.
043 * @param messages TODO
044 *
045 * @return the parsed object
046 * @throws ValidatorException
047 * if the specified text could not be parsed into an object.
048 */
049 public Object parse(IFormComponent field, ValidationMessages messages, String value) throws ValidatorException;
050 }