You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Angelo Chen <an...@yahoo.com.hk> on 2007/10/26 10:54:09 UTC

T5: inject ComponentResources in a service

Hi,

I injected ComponentResources in a service, but it's null, why?

public class MyServicesImp implements MyServices {

    @Inject
    private ComponentResources resources;

    public String createExternalPageLink(String pageName, Object context) {
        return getDomainName() + resources.createPageLink(pageName, true,
context);
    }
}
-- 
View this message in context: http://www.nabble.com/T5%3A-inject-ComponentResources-in-a-service-tf4695974.html#a13423186
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: inject ComponentResources in a service

Posted by Peter Stavrinides <p....@albourne.com>.
I suffered with this one for quite some time... you can *not provide 
ComponentResources to a service, you will end up with all sorts of funky 
errors, but I did however manage to create a navigation component and 
reuse it in there. The navigation component is part of my layout 
template, so I don't have to inject ComponentResources in every page.

Davor Hrg wrote:
> you can not inject component resources that way ... it is specific to a
> component
> so it's scope is not even PER_THREAD
>
> you will have to provide it in the method you call...
> and inject it into your page...
>
> look at it this way: if you have a dozen of components on your page
> and from one of the components you call your service....
> how would tapestry know for which of the dozen components you need the
> ComponentResources ?
>
> that's what I can tell you for now...
>
> Davor Hrg
>
> On 10/26/07, Angelo Chen <an...@yahoo.com.hk> wrote:
>   
>> hi davor,
>>
>> correction, the problem is ComponentResources used in the constructor, it
>> has this error:
>>
>> Exception constructing service 'MyServices': Error invoking constructor
>> org.bfe.myapp.t5.MyServicesImp(ComponentResources) (at
>> MyServicesImp.java:36) (for service 'MyServices'): No service implements
>> the
>> interface org.apache.tapestry.ComponentResources.
>>
>> seems ComponentResources can be used in this situation? Thanks.
>>
>> A.C.
>>
>>
>> Angelo Chen wrote:
>>     
>>> Hi,
>>>
>>> Thanks, now when there is only one parameter in the constructor, it
>>>       
>> works:
>>     
>>>  public MyServicesImp(ApplicationGlobals globals) {
>>>         this.globals = globals;
>>>     }
>>>
>>> but if I have this:
>>>
>>>  public MyServicesImp(ApplicationGlobals globals, ComponentResources
>>> resources) {
>>>         this.globals = globals;
>>>         this.resources = resources;
>>>     }
>>>
>>> it won't work, any hint?
>>>
>>> Thanks,
>>> A.C.
>>>
>>>
>>> Davor Hrg wrote:
>>>       
>>>> service do not get enhanced like pages do,
>>>>
>>>> services get dependacies through constructor...
>>>>
>>>> http://tapestry.apache.org/tapestry5/tapestry-ioc/service.html
>>>>
>>>> Davor Hrg
>>>>
>>>> On 10/26/07, Angelo Chen <an...@yahoo.com.hk> wrote:
>>>>         
>>>>> Hi,
>>>>>
>>>>> I injected ComponentResources in a service, but it's null, why?
>>>>>
>>>>> public class MyServicesImp implements MyServices {
>>>>>
>>>>>     @Inject
>>>>>     private ComponentResources resources;
>>>>>
>>>>>     public String createExternalPageLink(String pageName, Object
>>>>> context)
>>>>> {
>>>>>         return getDomainName() + resources.createPageLink(pageName,
>>>>> true,
>>>>> context);
>>>>>     }
>>>>> }
>>>>> --
>>>>> View this message in context:
>>>>>
>>>>>           
>> http://www.nabble.com/T5%3A-inject-ComponentResources-in-a-service-tf4695974.html#a13423186
>>     
>>>>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>>
>>>>>
>>>>>           
>>>>         
>>>       
>> --
>> View this message in context:
>> http://www.nabble.com/T5%3A-inject-ComponentResources-in-a-service-tf4695974.html#a13423903
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> 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


Re: T5: inject ComponentResources in a service

Posted by Davor Hrg <hr...@gmail.com>.
you can not inject component resources that way ... it is specific to a
component
so it's scope is not even PER_THREAD

you will have to provide it in the method you call...
and inject it into your page...

look at it this way: if you have a dozen of components on your page
and from one of the components you call your service....
how would tapestry know for which of the dozen components you need the
ComponentResources ?

that's what I can tell you for now...

Davor Hrg

On 10/26/07, Angelo Chen <an...@yahoo.com.hk> wrote:
>
>
> hi davor,
>
> correction, the problem is ComponentResources used in the constructor, it
> has this error:
>
> Exception constructing service 'MyServices': Error invoking constructor
> org.bfe.myapp.t5.MyServicesImp(ComponentResources) (at
> MyServicesImp.java:36) (for service 'MyServices'): No service implements
> the
> interface org.apache.tapestry.ComponentResources.
>
> seems ComponentResources can be used in this situation? Thanks.
>
> A.C.
>
>
> Angelo Chen wrote:
> >
> > Hi,
> >
> > Thanks, now when there is only one parameter in the constructor, it
> works:
> >
> >  public MyServicesImp(ApplicationGlobals globals) {
> >         this.globals = globals;
> >     }
> >
> > but if I have this:
> >
> >  public MyServicesImp(ApplicationGlobals globals, ComponentResources
> > resources) {
> >         this.globals = globals;
> >         this.resources = resources;
> >     }
> >
> > it won't work, any hint?
> >
> > Thanks,
> > A.C.
> >
> >
> > Davor Hrg wrote:
> >>
> >> service do not get enhanced like pages do,
> >>
> >> services get dependacies through constructor...
> >>
> >> http://tapestry.apache.org/tapestry5/tapestry-ioc/service.html
> >>
> >> Davor Hrg
> >>
> >> On 10/26/07, Angelo Chen <an...@yahoo.com.hk> wrote:
> >>>
> >>>
> >>> Hi,
> >>>
> >>> I injected ComponentResources in a service, but it's null, why?
> >>>
> >>> public class MyServicesImp implements MyServices {
> >>>
> >>>     @Inject
> >>>     private ComponentResources resources;
> >>>
> >>>     public String createExternalPageLink(String pageName, Object
> >>> context)
> >>> {
> >>>         return getDomainName() + resources.createPageLink(pageName,
> >>> true,
> >>> context);
> >>>     }
> >>> }
> >>> --
> >>> View this message in context:
> >>>
> http://www.nabble.com/T5%3A-inject-ComponentResources-in-a-service-tf4695974.html#a13423186
> >>> Sent from the Tapestry - User mailing list archive at Nabble.com.
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >>> For additional commands, e-mail: users-help@tapestry.apache.org
> >>>
> >>>
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/T5%3A-inject-ComponentResources-in-a-service-tf4695974.html#a13423903
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: inject ComponentResources in a service

Posted by Davor Hrg <hr...@gmail.com>.
Thats, just it:)
make a component, not a function ...

you'll copy pasete your function arround and iject component resources in
each page that uses it,
look at the ActionLink source and create an ExternalLink from it :)

Davor Hrg

On 10/26/07, Angelo Chen <an...@yahoo.com.hk> wrote:
>
>
> Hi Nick,
>
> yes, I just want to make a method to create external page link, well, I'll
> just create it on the page, was thinking I can make a generic function for
> that.
>
>
> Nick Westgate wrote:
> >
> > At a glance, you just want to call createPageLink on a Page.
> >
> > So you could inject the PagePool to get the page and go from there.
> > That's an internal service though ... can't see an obvious way to
> > do this without "more than a glance". ;-)
> >
> > Cheers,
> > Nick.
> >
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/T5%3A-inject-ComponentResources-in-a-service-tf4695974.html#a13425934
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: inject ComponentResources in a service

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Nick,

yes, I just want to make a method to create external page link, well, I'll
just create it on the page, was thinking I can make a generic function for
that. 


Nick Westgate wrote:
> 
> At a glance, you just want to call createPageLink on a Page.
> 
> So you could inject the PagePool to get the page and go from there.
> That's an internal service though ... can't see an obvious way to
> do this without "more than a glance". ;-)
> 
> Cheers,
> Nick.
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-inject-ComponentResources-in-a-service-tf4695974.html#a13425934
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: inject ComponentResources in a service

Posted by Davor Hrg <hr...@gmail.com>.
or, instead of creating a service,
just create an ExternalLink component like normal link already is

Hrg

On 10/26/07, Nick Westgate <ni...@key-planning.co.jp> wrote:
>
> At a glance, you just want to call createPageLink on a Page.
>
> So you could inject the PagePool to get the page and go from there.
> That's an internal service though ... can't see an obvious way to
> do this without "more than a glance". ;-)
>
> Cheers,
> Nick.
>
>
> Angelo Chen wrote:
> > hi davor,
> >
> > correction, the problem is ComponentResources used in the constructor,
> it
> > has this error:
> >
> > Exception constructing service 'MyServices': Error invoking constructor
> > org.bfe.myapp.t5.MyServicesImp(ComponentResources) (at
> > MyServicesImp.java:36) (for service 'MyServices'): No service implements
> the
> > interface org.apache.tapestry.ComponentResources.
> >
> > seems ComponentResources can be used in this situation? Thanks.
> >
> > A.C.
> >
> >
> > Angelo Chen wrote:
> >> Hi,
> >>
> >> Thanks, now when there is only one parameter in the constructor, it
> works:
> >>
> >>  public MyServicesImp(ApplicationGlobals globals) {
> >>         this.globals = globals;
> >>     }
> >>
> >> but if I have this:
> >>
> >>  public MyServicesImp(ApplicationGlobals globals, ComponentResources
> >> resources) {
> >>         this.globals = globals;
> >>         this.resources = resources;
> >>     }
> >>
> >> it won't work, any hint?
> >>
> >> Thanks,
> >> A.C.
> >>
> >>
> >> Davor Hrg wrote:
> >>> service do not get enhanced like pages do,
> >>>
> >>> services get dependacies through constructor...
> >>>
> >>> http://tapestry.apache.org/tapestry5/tapestry-ioc/service.html
> >>>
> >>> Davor Hrg
> >>>
> >>> On 10/26/07, Angelo Chen <an...@yahoo.com.hk> wrote:
> >>>>
> >>>> Hi,
> >>>>
> >>>> I injected ComponentResources in a service, but it's null, why?
> >>>>
> >>>> public class MyServicesImp implements MyServices {
> >>>>
> >>>>     @Inject
> >>>>     private ComponentResources resources;
> >>>>
> >>>>     public String createExternalPageLink(String pageName, Object
> >>>> context)
> >>>> {
> >>>>         return getDomainName() + resources.createPageLink(pageName,
> >>>> true,
> >>>> context);
> >>>>     }
> >>>> }
> >>>> --
> >>>> View this message in context:
> >>>>
> http://www.nabble.com/T5%3A-inject-ComponentResources-in-a-service-tf4695974.html#a13423186
> >>>> Sent from the Tapestry - User mailing list archive at Nabble.com.
> >>>>
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> 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
>
>

Re: T5: inject ComponentResources in a service

Posted by Nick Westgate <ni...@key-planning.co.jp>.
At a glance, you just want to call createPageLink on a Page.

So you could inject the PagePool to get the page and go from there.
That's an internal service though ... can't see an obvious way to
do this without "more than a glance". ;-)

Cheers,
Nick.


Angelo Chen wrote:
> hi davor,
> 
> correction, the problem is ComponentResources used in the constructor, it
> has this error:
> 
> Exception constructing service 'MyServices': Error invoking constructor
> org.bfe.myapp.t5.MyServicesImp(ComponentResources) (at
> MyServicesImp.java:36) (for service 'MyServices'): No service implements the
> interface org.apache.tapestry.ComponentResources.
> 
> seems ComponentResources can be used in this situation? Thanks.
> 
> A.C.
> 
> 
> Angelo Chen wrote:
>> Hi,
>>
>> Thanks, now when there is only one parameter in the constructor, it works:
>>
>>  public MyServicesImp(ApplicationGlobals globals) {
>>         this.globals = globals;
>>     }
>>
>> but if I have this:
>>
>>  public MyServicesImp(ApplicationGlobals globals, ComponentResources
>> resources) {
>>         this.globals = globals;
>>         this.resources = resources;
>>     }
>>
>> it won't work, any hint? 
>>
>> Thanks,
>> A.C.
>>
>>
>> Davor Hrg wrote:
>>> service do not get enhanced like pages do,
>>>
>>> services get dependacies through constructor...
>>>
>>> http://tapestry.apache.org/tapestry5/tapestry-ioc/service.html
>>>
>>> Davor Hrg
>>>
>>> On 10/26/07, Angelo Chen <an...@yahoo.com.hk> wrote:
>>>>
>>>> Hi,
>>>>
>>>> I injected ComponentResources in a service, but it's null, why?
>>>>
>>>> public class MyServicesImp implements MyServices {
>>>>
>>>>     @Inject
>>>>     private ComponentResources resources;
>>>>
>>>>     public String createExternalPageLink(String pageName, Object
>>>> context)
>>>> {
>>>>         return getDomainName() + resources.createPageLink(pageName,
>>>> true,
>>>> context);
>>>>     }
>>>> }
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/T5%3A-inject-ComponentResources-in-a-service-tf4695974.html#a13423186
>>>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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


Re: T5: inject ComponentResources in a service

Posted by Angelo Chen <an...@yahoo.com.hk>.
hi davor,

correction, the problem is ComponentResources used in the constructor, it
has this error:

Exception constructing service 'MyServices': Error invoking constructor
org.bfe.myapp.t5.MyServicesImp(ComponentResources) (at
MyServicesImp.java:36) (for service 'MyServices'): No service implements the
interface org.apache.tapestry.ComponentResources.

seems ComponentResources can be used in this situation? Thanks.

A.C.


Angelo Chen wrote:
> 
> Hi,
> 
> Thanks, now when there is only one parameter in the constructor, it works:
> 
>  public MyServicesImp(ApplicationGlobals globals) {
>         this.globals = globals;
>     }
> 
> but if I have this:
> 
>  public MyServicesImp(ApplicationGlobals globals, ComponentResources
> resources) {
>         this.globals = globals;
>         this.resources = resources;
>     }
> 
> it won't work, any hint? 
> 
> Thanks,
> A.C.
> 
> 
> Davor Hrg wrote:
>> 
>> service do not get enhanced like pages do,
>> 
>> services get dependacies through constructor...
>> 
>> http://tapestry.apache.org/tapestry5/tapestry-ioc/service.html
>> 
>> Davor Hrg
>> 
>> On 10/26/07, Angelo Chen <an...@yahoo.com.hk> wrote:
>>>
>>>
>>> Hi,
>>>
>>> I injected ComponentResources in a service, but it's null, why?
>>>
>>> public class MyServicesImp implements MyServices {
>>>
>>>     @Inject
>>>     private ComponentResources resources;
>>>
>>>     public String createExternalPageLink(String pageName, Object
>>> context)
>>> {
>>>         return getDomainName() + resources.createPageLink(pageName,
>>> true,
>>> context);
>>>     }
>>> }
>>> --
>>> View this message in context:
>>> http://www.nabble.com/T5%3A-inject-ComponentResources-in-a-service-tf4695974.html#a13423186
>>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-inject-ComponentResources-in-a-service-tf4695974.html#a13423903
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: inject ComponentResources in a service

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi,

Thanks, now when there is only one parameter in the constructor, it works:

 public MyServicesImp(ApplicationGlobals globals) {
        this.globals = globals;
    }

but if I have this:

 public MyServicesImp(ApplicationGlobals globals, ComponentResources
resources) {
        this.globals = globals;
        this.resources = resources;
    }

it won't work, any hint? 

Thanks,
A.C.


Davor Hrg wrote:
> 
> service do not get enhanced like pages do,
> 
> services get dependacies through constructor...
> 
> http://tapestry.apache.org/tapestry5/tapestry-ioc/service.html
> 
> Davor Hrg
> 
> On 10/26/07, Angelo Chen <an...@yahoo.com.hk> wrote:
>>
>>
>> Hi,
>>
>> I injected ComponentResources in a service, but it's null, why?
>>
>> public class MyServicesImp implements MyServices {
>>
>>     @Inject
>>     private ComponentResources resources;
>>
>>     public String createExternalPageLink(String pageName, Object context)
>> {
>>         return getDomainName() + resources.createPageLink(pageName, true,
>> context);
>>     }
>> }
>> --
>> View this message in context:
>> http://www.nabble.com/T5%3A-inject-ComponentResources-in-a-service-tf4695974.html#a13423186
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-inject-ComponentResources-in-a-service-tf4695974.html#a13423821
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: inject ComponentResources in a service

Posted by Davor Hrg <hr...@gmail.com>.
service do not get enhanced like pages do,

services get dependacies through constructor...

http://tapestry.apache.org/tapestry5/tapestry-ioc/service.html

Davor Hrg

On 10/26/07, Angelo Chen <an...@yahoo.com.hk> wrote:
>
>
> Hi,
>
> I injected ComponentResources in a service, but it's null, why?
>
> public class MyServicesImp implements MyServices {
>
>     @Inject
>     private ComponentResources resources;
>
>     public String createExternalPageLink(String pageName, Object context)
> {
>         return getDomainName() + resources.createPageLink(pageName, true,
> context);
>     }
> }
> --
> View this message in context:
> http://www.nabble.com/T5%3A-inject-ComponentResources-in-a-service-tf4695974.html#a13423186
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>