org.apache.myfaces.orchestra.dynaForm.lib
Class ObjectSerializationConverter

java.lang.Object
  extended by org.apache.myfaces.orchestra.dynaForm.lib.ObjectSerializationConverter
All Implemented Interfaces:
javax.faces.convert.Converter

public class ObjectSerializationConverter
extends Object
implements javax.faces.convert.Converter

Converter that can map a Serializable object into a plain java String.

This works like the standard java Serializable process, except that the resulting byte-array is then base64-encoded, ie is a String containing only ascii characters. The resulting value can safely be passed around as the "value" of a select-list, or a value embedded in a hidden field etc.

In particular, this allows the value of a SelectItem to be an object rather than a String, and the serialized form of a small object (such as the key class of a persistent entity) to be passed as a url query parameter.

Of course the object should not be too complicated, otherwise the string representation will be rather large!


Field Summary
static NullObject SELECT_NULL_OBJECT
           
 
Constructor Summary
ObjectSerializationConverter()
           
 
Method Summary
 Object getAsObject(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, String value)
          Given a String that was previously created by the getAsString method on this class, "deserialize" the content of the string into a new Object instance.
 String getAsString(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value)
          Return a serialized representation of the provided value, as a String type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SELECT_NULL_OBJECT

public static final NullObject SELECT_NULL_OBJECT
Constructor Detail

ObjectSerializationConverter

public ObjectSerializationConverter()
Method Detail

getAsObject

public Object getAsObject(javax.faces.context.FacesContext context,
                          javax.faces.component.UIComponent component,
                          String value)
                   throws javax.faces.convert.ConverterException
Given a String that was previously created by the getAsString method on this class, "deserialize" the content of the string into a new Object instance.

See method getAsString for more details.

Specified by:
getAsObject in interface javax.faces.convert.Converter
Throws:
javax.faces.convert.ConverterException

getAsString

public String getAsString(javax.faces.context.FacesContext context,
                          javax.faces.component.UIComponent component,
                          Object value)
                   throws javax.faces.convert.ConverterException
Return a serialized representation of the provided value, as a String type.

The provided value is serialized into a byte-array using normal java serialization, and the array is then base64-encoded. The result is a String that is safe to pass around in places that expect a String. The returned value can later be passed to the getAsToObject method of this class to recreate the value passed here.

The provided object must implement the Serializable interface.

Specified by:
getAsString in interface javax.faces.convert.Converter
Throws:
javax.faces.convert.ConverterException


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.