Skip to main content
Last updated September 07, 2011 22:47, by Kin-man Chung
Feedicon  
==Type Converter== In EL 3.0, type coercions are controlled by the abstract class [http://java.net/projects/el-spec/sources/source-code/content/trunk/api/src/main/java/javax/el/TypeConverter.java TypeConverter]. [http://java.net/projects/el-spec/sources/source-code/content/trunk/api/src/main/java/javax/el/ELContext.java ELContext] contains an instance of this class, and is used for all type coercions in expression evaluations. [http://java.net/projects/el-spec/sources/source-code/content/trunk/api/src/main/java/javax/el/StandardTypeConverter.java 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 [http://java.net/projects/el-spec/sources/source-code/content/trunk/api/src/main/java/javax/el/ELManager.java ELManager]'s new method setTypeConverter. <pre name="java"> 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); } }); </pre>
 
 
Close
loading
Please Confirm
Close