Skip to main content
This revision made September 07, 2011 22:47, by Kin-man Chung
« earlier revision revert to this « later revision

Type Converter

In EL 3.0, type coercions are controlled by the abstract class TypeConverter. ELContext contains an instance of this class, and is used for all type coercions in expression evaluations.

StandardTypeConverter extends TypeConverter to implemented the conversion rules in the spec. To plug in a customized TypeConverter, this class can be extended to provide conversions for a specific source and target type, using ELManager's new method setTypeConverter.

    elManager.setTypeConverter(new StandardTypeConverter {
        public <T> T coerceToType(Object obj, Class<T> targetType) {
            if ((obj instanceof Foo && targetType == String.class) {
                return /*specific Foo to String conversion*/;
            }
            return super.coerceToType(obj, targetType);
        }
    });

            
 
 
Close
loading
Please Confirm
Close