Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 // Copyright 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
 //     http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.tapestry5;

Used to convert server side values to client-side strings. This is used when generating a EventContext as part of a URL, or when components (such as org.apache.tapestry5.corelib.components.Select) generated other client-side strings.

Often a custom implementation is needed for entity type objects, where the toClient(java.lang.Object) method extracts a primary key, and the toValue(java.lang.String) re-acquires the corresponding entity object.

public interface ValueEncoder<V>
{
    
Converts a value into a client-side representation. The value should be parseable by toValue(java.lang.String). In some cases, what is returned is an identifier used to locate the true object, rather than a string representation of the value itself.

Parameters:
value to be encoded
Returns:
a string representation of the value, or the value's identity
    String toClient(V value);

    
Converts a client-side representation, provided by toClient(java.lang.Object), back into a server-side value.

Parameters:
clientValue string representation of the value's identity
Returns:
the corresponding entity, or null if not found
    V toValue(String clientValue);
New to GrepCode? Check out our FAQ X