You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Andrias Sundskarð <as...@amc.dk> on 2017/06/01 07:12:57 UTC

RE: Replacing default type coercer

That might work, but I'm thinking that the type coercer solution is more like "code once, fix every page", right? Or am I misunderstanding you reply? Could you provide some code example?

However, the question on how to replace an existing type coercer remains. Is that not possible?

-----Original Message-----
From: Thiago H. de Paula Figueiredo [mailto:thiagohp@gmail.com] 
Sent: 31. maj 2017 20:51
To: Tapestry users <us...@tapestry.apache.org>
Subject: Re: Replacing default type coercer

Hi!

Why don't you just pass a GridDataSource directly instead of relying on having your collection coerced to it?

On Wed, May 31, 2017 at 10:41 AM, Andrias Sundskarð <as...@amc.dk> wrote:

> Hi, guys.
>
> I'm using tapestry 5.3.8.
>
> I need a different grid sorting than the one provided in 
> "CollectionGridDataSource".
> I contribute a custom type coercer like this:
>
> public static void contributeTypeCoercer(Configuration<CoercionTuple>
> configuration)
> {
>                              
> configuration.add(CoercionTuple.create(Collection.class,
> GridDataSource.class,
>                                      new Coercion<Collection,
> GridDataSource>()
>                                      {
>                                                                   @Override
>                                                                   
> public GridDataSource coerce(Collection input)
>                                                                   {
>
>                      return new MyCollectionGridDataSource(input);
>                                                                   }
>                                      })); }
>
> My code seems to work without issues, but at random times 
> "MyCollectionGridDataSource" is not being used. These times the 
> standard "CollectionGridDataSource" is used instead. I have verified 
> this by setting break point in both classes.
>
> Configuration list before adding custom type coercer:
> org.apache.tapestry5.ComponentResources --> org.apache.tapestry5.
> PropertyOverrides
> String --> org.apache.tapestry5.SelectModel java.util.Map --> 
> org.apache.tapestry5.SelectModel java.util.Collection --> 
> org.apache.tapestry5.grid.GridDataSource
> null --> org.apache.tapestry5.grid.GridDataSource
> java.util.List --> org.apache.tapestry5.SelectModel String --> 
> java.util.regex.Pattern 
> org.apache.tapestry5.runtime.ComponentResourcesAware --> 
> org.apache.tapestry5.ComponentResources
> String --> org.apache.tapestry5.Renderable 
> org.apache.tapestry5.Renderable --> org.apache.tapestry5.Block String 
> --> java.text.DateFormat String --> org.apache.tapestry5.ioc.Resource 
> org.apache.tapestry5.Renderable --> org.apache.tapestry5.runtime.
> RenderCommand
> java.util.Date --> java.util.Calendar
> org.apache.tapestry5.ioc.Resource --> org.apache.tapestry5.services.
> dynamic.DynamicTemplate
> org.apache.tapestry5.Asset --> org.apache.tapestry5.ioc.Resource 
> String --> org.apache.tapestry5.corelib.ClientValidation
> org.apache.tapestry5.services.ComponentClassTransformWorker -->
> org.apache.tapestry5.services.transform.ComponentClassTransformWorker2
> org.apache.tapestry5.ValueEncoder --> org.apache.tapestry5.services.
> ValueEncoderFactory
> org.apache.tapestry5.services.InjectionProvider -->
> org.apache.tapestry5.services.transform.InjectionProvider2
>
> and after:
> org.apache.tapestry5.ComponentResources --> org.apache.tapestry5.
> PropertyOverrides
> String --> org.apache.tapestry5.SelectModel java.util.Map --> 
> org.apache.tapestry5.SelectModel java.util.Collection --> 
> org.apache.tapestry5.grid.GridDataSource
> null --> org.apache.tapestry5.grid.GridDataSource
> java.util.List --> org.apache.tapestry5.SelectModel String --> 
> java.util.regex.Pattern 
> org.apache.tapestry5.runtime.ComponentResourcesAware --> 
> org.apache.tapestry5.ComponentResources
> String --> org.apache.tapestry5.Renderable 
> org.apache.tapestry5.Renderable --> org.apache.tapestry5.Block String 
> --> java.text.DateFormat String --> org.apache.tapestry5.ioc.Resource 
> org.apache.tapestry5.Renderable --> org.apache.tapestry5.runtime.
> RenderCommand
> java.util.Date --> java.util.Calendar
> org.apache.tapestry5.ioc.Resource --> org.apache.tapestry5.services.
> dynamic.DynamicTemplate
> org.apache.tapestry5.Asset --> org.apache.tapestry5.ioc.Resource 
> String --> org.apache.tapestry5.corelib.ClientValidation
> org.apache.tapestry5.services.ComponentClassTransformWorker -->
> org.apache.tapestry5.services.transform.ComponentClassTransformWorker2
> org.apache.tapestry5.ValueEncoder --> org.apache.tapestry5.services.
> ValueEncoderFactory
> org.apache.tapestry5.services.InjectionProvider -->
> org.apache.tapestry5.services.transform.InjectionProvider2
> java.util.Collection --> org.apache.tapestry5.grid.GridDataSource
>
> As seen here it seems that my custom coercer does not replace the 
> existing one.
>
> How can I replace the existing type coercer with my own?
>



--
Thiago

Re: Replacing default type coercer

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Thu, Jun 1, 2017 at 4:12 AM, Andrias Sundskarð <as...@amc.dk> wrote:

> That might work, but I'm thinking that the type coercer solution is more
> like "code once, fix every page", right?


Right. Or you could create a new class wrapping a collection and contribute
a coercion for it to GridDataSource, avoiding trying to override an
existing coercion.


> However, the question on how to replace an existing type coercer remains.
> Is that not possible?
>

I may be wrong and I haven't tested, but I don't think so.

I'm very curious on why you want or need to override this coercion in first
place.