You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Alejandro Scandroli <al...@gmail.com> on 2008/04/06 18:32:02 UTC
Re: .class coercion
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 <la...@codelutin.com> 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 <la...@codelutin.com>
> http://www.codelutin.com
> tel : 02 40 50 29 28 / fax : 09 59 92 29 28
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org