You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ken in Nashua <kc...@live.com> on 2013/05/20 04:59:49 UTC

trying to avoid code bloat

Hi Folks,

Can i construct an abstract page and inject a bunch of services and then have derived instances extend from that ?

I tried it and seeing some weird class format errors.

I did it with my model entities.

trying to do it with pages and injectables.

public abstract class AbstractPage implements org.tynamo.examples.pphl.pages.interfaces.IAbstractPage, ExceptionReporter {
    
    /**
     * services and injectables
     */
    @Inject
    protected Logger logger;
    
    @Inject
    protected DescriptorService descriptorService;

    @Inject
    protected HibernatePersistenceService hibernatePersistenceService;

    @Inject
    protected Messages messages;

    @Inject
    protected PropertyAccess adapter;    
    
    @Inject
    protected ValueEncoderSource valueEncoderSource;
    
    @Inject
    protected ComponentDefaultProvider cdp; 
   
    @Inject
    protected ComponentResources resources;

    @Inject
    protected ApplicationStateManager applicationStateManager;

    @Inject
    protected PersistenceService persistenceService;

    @Inject
    protected SecurityService securityService;

 		 	   		  

Re: trying to avoid code bloat

Posted by Peter Stavrinides <P....@albourne.com>.
stick them in the base package, extend the class and it works great 

----- Original Message -----

From: "Barry Books" <tr...@gmail.com> 
To: "Tapestry users" <us...@tapestry.apache.org> 
Sent: Monday, 20 May, 2013 2:31:18 PM 
Subject: Re: trying to avoid code bloat 

I would not use an Abstract page for this purpose. The first problem is 
protected will not work because the pages will not have the same package. I 
would create a service with these services and just inject that. So your 
page would just have 

@Inject 
private Services services; 

and your service will have a constructer and get methods: 

class Services(Service1 service1, ...) { 
this.service1 = service1; 
} 

public Service1 getService1() { 
return service1; 
} 




On Sun, May 19, 2013 at 9:59 PM, Ken in Nashua <kc...@live.com> wrote: 

> Hi Folks, 
> 
> Can i construct an abstract page and inject a bunch of services and then 
> have derived instances extend from that ? 
> 
> I tried it and seeing some weird class format errors. 
> 
> I did it with my model entities. 
> 
> trying to do it with pages and injectables. 
> 
> public abstract class AbstractPage implements 
> org.tynamo.examples.pphl.pages.interfaces.IAbstractPage, ExceptionReporter { 
> 
> /** 
> * services and injectables 
> */ 
> @Inject 
> protected Logger logger; 
> 
> @Inject 
> protected DescriptorService descriptorService; 
> 
> @Inject 
> protected HibernatePersistenceService hibernatePersistenceService; 
> 
> @Inject 
> protected Messages messages; 
> 
> @Inject 
> protected PropertyAccess adapter; 
> 
> @Inject 
> protected ValueEncoderSource valueEncoderSource; 
> 
> @Inject 
> protected ComponentDefaultProvider cdp; 
> 
> @Inject 
> protected ComponentResources resources; 
> 
> @Inject 
> protected ApplicationStateManager applicationStateManager; 
> 
> @Inject 
> protected PersistenceService persistenceService; 
> 
> @Inject 
> protected SecurityService securityService; 
> 
> 


Re: trying to avoid code bloat

Posted by Barry Books <tr...@gmail.com>.
I would not use an Abstract page for this purpose. The first problem is
protected will not work because the pages will not have the same package. I
would create a service with these services and just inject that. So your
page would just have

@Inject
private Services services;

and your service will have a constructer and get methods:

class Services(Service1 service1, ...) {
this.service1 = service1;
}

public Service1 getService1() {
return service1;
}




On Sun, May 19, 2013 at 9:59 PM, Ken in Nashua <kc...@live.com> wrote:

> Hi Folks,
>
> Can i construct an abstract page and inject a bunch of services and then
> have derived instances extend from that ?
>
> I tried it and seeing some weird class format errors.
>
> I did it with my model entities.
>
> trying to do it with pages and injectables.
>
> public abstract class AbstractPage implements
> org.tynamo.examples.pphl.pages.interfaces.IAbstractPage, ExceptionReporter {
>
>     /**
>      * services and injectables
>      */
>     @Inject
>     protected Logger logger;
>
>     @Inject
>     protected DescriptorService descriptorService;
>
>     @Inject
>     protected HibernatePersistenceService hibernatePersistenceService;
>
>     @Inject
>     protected Messages messages;
>
>     @Inject
>     protected PropertyAccess adapter;
>
>     @Inject
>     protected ValueEncoderSource valueEncoderSource;
>
>     @Inject
>     protected ComponentDefaultProvider cdp;
>
>     @Inject
>     protected ComponentResources resources;
>
>     @Inject
>     protected ApplicationStateManager applicationStateManager;
>
>     @Inject
>     protected PersistenceService persistenceService;
>
>     @Inject
>     protected SecurityService securityService;
>
>

RE: trying to avoid code bloat

Posted by Ken in Nashua <kc...@live.com>.
Thanks Joakim... I noticed that. I didnt believe the error... but its good to have a confirmation.

I will try it again in that pages dir.
 		 	   		  

Re: trying to avoid code bloat

Posted by Joakim Olsson <jo...@unbound.se>.
Base-classes need to be located in a package called base on the same level
as pages, components, mixins and services.

/Joakim



On Mon, May 20, 2013 at 4:59 AM, Ken in Nashua <kc...@live.com> wrote:

> Hi Folks,
>
> Can i construct an abstract page and inject a bunch of services and then
> have derived instances extend from that ?
>
> I tried it and seeing some weird class format errors.
>
> I did it with my model entities.
>
> trying to do it with pages and injectables.
>
> public abstract class AbstractPage implements
> org.tynamo.examples.pphl.pages.interfaces.IAbstractPage, ExceptionReporter {
>
>     /**
>      * services and injectables
>      */
>     @Inject
>     protected Logger logger;
>
>     @Inject
>     protected DescriptorService descriptorService;
>
>     @Inject
>     protected HibernatePersistenceService hibernatePersistenceService;
>
>     @Inject
>     protected Messages messages;
>
>     @Inject
>     protected PropertyAccess adapter;
>
>     @Inject
>     protected ValueEncoderSource valueEncoderSource;
>
>     @Inject
>     protected ComponentDefaultProvider cdp;
>
>     @Inject
>     protected ComponentResources resources;
>
>     @Inject
>     protected ApplicationStateManager applicationStateManager;
>
>     @Inject
>     protected PersistenceService persistenceService;
>
>     @Inject
>     protected SecurityService securityService;
>
>