Replacing default type coercer

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Replacing default type coercer

Andrias Sundskarð
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?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Replacing default type coercer

Thiago H de Paula Figueiredo
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ð <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Replacing default type coercer

Andrias Sundskarð
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:[hidden email]]
Sent: 31. maj 2017 20:51
To: Tapestry users <[hidden email]>
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ð <[hidden email]> 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

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Replacing default type coercer

Ilya Obshadko-2
In reply to this post by Andrias Sundskarð
I had similar issue when Grid lost its custom settings (though it wasn’t
related to coercer).
I solved it by directly calling grid.reset() in my event handler.

On Wed, May 31, 2017 at 4:41 PM, Andrias Sundskarð <[hidden email]> 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?
>



--
Ilya Obshadko
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Replacing default type coercer

Thiago H de Paula Figueiredo
In reply to this post by Andrias Sundskarð
On Thu, Jun 1, 2017 at 4:12 AM, Andrias Sundskarð <[hidden email]> 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.
Loading...