Hi Gabriel,

I know this message is a little bit old, but I just found it today.
Here is my Class coercion code:

        public static void contributeTypeCoercer(Configuration<CoercionTuple>
configuration)
        {
                Coercion<Class, String> classToString = new Coercion<Class, 
String>()
                {
                        public String coerce(Class clazz)
                        {
                                return clazz.getName();
                        }
                };

                Coercion<String, Class> stringToClass = new Coercion<String, 
Class>()
                {
                        public Class coerce(String className)
                        {
                                try
                                {
                                        return Class.forName(className);

                                } catch (ClassNotFoundException e)
                                {
                                        throw new RuntimeException("Coercion 
failed!", e);
                                }
                        }
                };

                configuration.add(new CoercionTuple<Class, String>(Class.class,
String.class, classToString));
                configuration.add(new CoercionTuple<String, Class>(String.class,
Class.class, stringToClass));
        }



--
Alejandro Scandroli - http://weblog.amneris.es/
Amneris: We build process-driven web applications.
http://www.amneris.es


On Mon, Feb 25, 2008 at 4:04 PM, Gabriel Landais <[EMAIL PROTECTED]> wrote:
> Hello,
>  I've a bean with a Class<?> property. I want to display the simple name,
> without success.
>
>  First it understands well that (T5.0.10) :
>
>    public static void
> contributeDefaultDataTypeAnalyzer(MappedConfiguration<Class<?>, String>
> configuration) {
>        configuration.add(Class.class, "text");
>    }
>
>  It display something like "class my.package.entity".
>  As I'm trying to contribute my own TypeCoercer, it looks like it is not
> used :
>
>    public static void contributeTypeCoercer(Configuration<CoercionTuple>
> configuration) {
>        Coercion<Class, String> coercionClassString = new Coercion<Class,
> String>() {
>            public String coerce(Class input) {
>                if (input == null) {
>                    return "";
>                }
>                // my code normally looksup an enum
>                return input.getSimpleName();
>            }
>        };
>        configuration.add(new CoercionTuple<Class, String>(Class.class,
> String.class, coercionClassString));
>    }
>
>  Any idea? I've added a read only property for the moment, perhaps a best
> way...
>
>  --
>  Gabriel <[EMAIL PROTECTED]>
>  http://www.codelutin.com
>  tel : 02 40 50 29 28 / fax : 09 59 92 29 28
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: [EMAIL PROTECTED]
>  For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to