01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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;
16:
17: import org.apache.tapestry.corelib.components.Select;
18:
19: /**
20: * Used by {@link Select} (and similar components) to encode server side values into client-side
21: * strings, and back.
22: * <p>
23: * Most often a custom implementation is needed for entity type objects, where the
24: * {@link #toClient(Object)} method extracts a primary key, and the {@link #toValue(String)}
25: * re-acquires the corresponding entity object.
26: *
27: * @see SelectModel
28: */
29: public interface ValueEncoder<V> {
30: /**
31: * Converts a value into a client-side representation. The value should be parseable by
32: * {@link #toValue(String)}. In some cases, what is returned is an identifier used to locate
33: * the true object, rather than a string representation of the value itself.
34: *
35: * @param value
36: * to be encoded
37: * @return a string representation of the value, or the value's identity
38: */
39: String toClient(V value);
40:
41: /**
42: * Converts a client-side representation, provided by {@link #toClient(Object)}, back into a
43: * server-side value.
44: *
45: * @param clientValue
46: * string representation of the value's identity
47: * @return the corresponding entity, or null if not found
48: */
49: V toValue(String clientValue);
50: }
|