Save This Page
Home » tapestry-src-5.0.19 » org.apache.tapestry5 » [javadoc | source]
    1   // Copyright 2007, 2008 The Apache Software Foundation
    2   //
    3   // Licensed under the Apache License, Version 2.0 (the "License");
    4   // you may not use this file except in compliance with the License.
    5   // You may obtain a copy of the License at
    6   //
    7   //     http://www.apache.org/licenses/LICENSE-2.0
    8   //
    9   // 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.tapestry5;
   16   
   17   /**
   18    * Used to convert server side values to client-side strings.  This is used when generating a {@link
   19    * org.apache.tapestry5.EventContext} as part of a URL, or when components (such as {@link
   20    * org.apache.tapestry5.corelib.components.Select}) generated other client-side strings.
   21    * <p/>
   22    * Often a custom implementation is needed for entity type objects, where the {@link #toClient(Object)} method extracts
   23    * a primary key, and the {@link #toValue(String)} re-acquires the corresponding entity object.
   24    *
   25    * @see SelectModel
   26    * @see org.apache.tapestry5.services.ValueEncoderSource
   27    * @see PrimaryKeyEncoder
   28    */
   29   public interface ValueEncoder<V>
   30   {
   31       /**
   32        * Converts a value into a client-side representation. The value should be parseable by {@link #toValue(String)}. In
   33        * some cases, what is returned is an identifier used to locate the true object, rather than a string representation
   34        * of the value itself.
   35        *
   36        * @param value 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 server-side value.
   43        *
   44        * @param clientValue string representation of the value's identity
   45        * @return the corresponding entity, or null if not found
   46        */
   47       V toValue(String clientValue);
   48   }

Save This Page
Home » tapestry-src-5.0.19 » org.apache.tapestry5 » [javadoc | source]