You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by David Kendall <da...@lithium.com> on 2007/11/17 04:10:36 UTC

T5: Decorating A Service In a Sub Module

I am working on a sizable application where I am trying to decorate the
PageRenderRequestHandler service. I have two modules - a Main Module and
a Sub Module. The Sub Module is loaded using the @SubModule annotation
on the Main Module. Both modules are trying to decorate the
PageRenderRequestHandler

The problem is that I am unable to get tapestry to execute the
decorating code in the SubModule. The sub module decorator looks like
this....


public PageRenderRequestHandler decoratePageRenderRequestHandler

             (Class<PageRenderRequestHandler> serviceInterace,
                         		Object delegateObj {
		final PageRenderRequestHandler castDelegate =
(PageRenderRequestHandler) delegateObj;
	return new PageRenderRequestHandler() {
		public ActionResponseGenerator handle(String
logicalPageName, String[] context) {
			// my decorator specific code is removed here

			ActionResponseGenerator handle =
castDelegate.handle(logicalPageName, context);

			return handle;
		}
	};

}


Whenever the code is supposed to run - I get the following message
showing up in the log...

"Could not add object with duplicate id 'PageRenderRequestHandler'.  The
duplicate object has been ignored."

The Main Module decorator is functioning correctly.

The documentation on decorators mentions the putting @Order annotation
on the sub module. However - when I annotate my decorator builder method
with  @Order("before:*") or @Order("after:*") - I get the same logging
message and still the Sub Module decorator is not being executed.

Is anyone familiar with how to correctly specify multiple decorators on
a single service? Any help would be appreciated.

Thanks.

David Kendall
Software Architect 
Lithium Technologies






---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Decorating A Service In a Sub Module

Posted by Massimo Lusetti <ml...@gmail.com>.
On Nov 19, 2007 6:40 PM, David Kendall <da...@lithium.com> wrote:

> Is there anyone on this list who does have experience with using
> decorators in a sub-module and can tell me what I am doing wrong - or
> who can verify this is a bug in T5?

I'm using decorators in a sub module, BTW i don't see differences
between module and sub module.
I'm using decorator for transactional (db with hibernate) features and
it works, honestly i got only one decorator per service so i cannot
comment on 'more then one decorato' stuff.

Regards
-- 
Massimo
http://meridio.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: T5: Decorating A Service In a Sub Module

Posted by David Kendall <da...@lithium.com>.
> I haven't used decoration before, but I'm guessing that even with 
> decorators you must still provide a service id.

Chris:

Thanks for your reply. As I understand decorators - the service id is
the same as the service it is decorating. This is because a decorator is
a wrapper around a service and implements the same interface as the
service. The calling code doesn't know that it is interacting with a
decorator. 

We are using decorators extensively in our code base - but this is the
first time we have multiple decorators on a single service.

Perhaps I am missing something here. If so - maybe you could elaborate
on how the service id should be defined. 

In the meantime - I have simplified my code a little in the hopes that
simplicity helps highlight the problem. Here is my current code in the
sub-module - this code never gets executed and consequently - my
decorator code in PageRenderRequestHandlerDecorator is not invoked
either.


public PageRenderRequestHandler
decoratePageRenderRequestHandler(Class<PageRenderRequestHandler>
serviceInterace, Object delegateObj) {

  PageRenderRequestHandler castDelegate = (PageRenderRequestHandler)
delegateObj;

  PageRenderRequestHandlerDecorator decorator = new
PageRenderRequestHandlerDecorator(castDelegate);
	return decorator;

}


Is there anyone on this list who does have experience with using
decorators in a sub-module and can tell me what I am doing wrong - or
who can verify this is a bug in T5?

Thanks.

David Kendall
Software Architect 
Lithium Technologies


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Decorating A Service In a Sub Module

Posted by Chris Lewis <ch...@bellsouth.net>.
I think its just an ID problem, as the exception suggests. I haven't 
used decoration before, but I'm guessing that even with decorators you 
must still provide a service id. In your example you do not, so its 
probably getting assigned the simple class name of your implementation 
(PageRenderRequestHandler). When you decorate the same service without 
explicitly providing an id, you get 2 decorators with the same id, and 
thus a collision.

I'm basing this on service docs and 
(http://tapestry.apache.org/tapestry5/tapestry-ioc/decorator.html). 
Again I haven't used decoration so I'm assuming that the same principles 
apply (your exception suggests it as well).

sincerely,
chris

David Kendall wrote:
> I am working on a sizable application where I am trying to decorate the
> PageRenderRequestHandler service. I have two modules - a Main Module and
> a Sub Module. The Sub Module is loaded using the @SubModule annotation
> on the Main Module. Both modules are trying to decorate the
> PageRenderRequestHandler
>
> The problem is that I am unable to get tapestry to execute the
> decorating code in the SubModule. The sub module decorator looks like
> this....
>
>
> public PageRenderRequestHandler decoratePageRenderRequestHandler
>
>              (Class<PageRenderRequestHandler> serviceInterace,
>                          		Object delegateObj {
> 		final PageRenderRequestHandler castDelegate =
> (PageRenderRequestHandler) delegateObj;
> 	return new PageRenderRequestHandler() {
> 		public ActionResponseGenerator handle(String
> logicalPageName, String[] context) {
> 			// my decorator specific code is removed here
>
> 			ActionResponseGenerator handle =
> castDelegate.handle(logicalPageName, context);
>
> 			return handle;
> 		}
> 	};
>
> }
>
>
> Whenever the code is supposed to run - I get the following message
> showing up in the log...
>
> "Could not add object with duplicate id 'PageRenderRequestHandler'.  The
> duplicate object has been ignored."
>
> The Main Module decorator is functioning correctly.
>
> The documentation on decorators mentions the putting @Order annotation
> on the sub module. However - when I annotate my decorator builder method
> with  @Order("before:*") or @Order("after:*") - I get the same logging
> message and still the Sub Module decorator is not being executed.
>
> Is anyone familiar with how to correctly specify multiple decorators on
> a single service? Any help would be appreciated.
>
> Thanks.
>
> David Kendall
> Software Architect 
> Lithium Technologies
>
>
>
>
>
>
> ---------------------------------------------------------------------
> 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