You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Michael Maier <mi...@vivai.de> on 2007/05/04 11:37:23 UTC
T5: How to inject a service into a component?
Hi List,
I'm trying to inject via @Inject annotation a service (internal
service RequestPageCache) into a component:
public class Menu {
@Inject("RequestPageCache")
RequestPageCache requestPageCache;
public String getPageName() {
ComponentResources pageResources= resources.getPage
().getComponentResources();
String pageClassName= pageResources.getCompleteId();
Page page= requestPageCache.getByClassName(pageClassName);
return page.getName();
}
}
so...while rendering the page with the menu component
<div id="leftside">
<div id="menu">
<ul>
<li>
${pageName}
</li>
</ul>
</div>
</div>
a null pointer exception occures, because "requestPageCache" is null.
What is getting wrong? Is RequestPageCache not injectable?
What I want: I just try to get the page of the component. Then the
menu component should highlight by providing a special css-class the
corresponding menu item of the <ul><li>-list for the active page.
Therefore the menu component must know the current page that is
rendered. In Tapestry 3 is just call the method getPage of the
component. Now every component has no parent class...
While we are talking about injection: the docs are a little bit
confusing:
@Inject
@Service("xxx") (which did not work with 5.0.3, because Service
annotation does not exist)
or
@Inject("xxx")
or
@Inject( "service:xxx" ) (what kind of prefixes (service:) exists and
what meaning have they?)
sometimes:
@Inject ("alias:request" )...is there somewhere a list with all
objects that are able to be injected from tapestry-core?
thanks for any help
cheers
Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5: How to inject a service into a component?
Posted by Howard Lewis Ship <hl...@gmail.com>.
You should be seeing some logged console messages about private variables.
Only private instance variables may have annotations on them; yours is
"package private" not private.
On 5/4/07, Michael Maier <mi...@vivai.de> wrote:
>
> Hi List,
>
> I'm trying to inject via @Inject annotation a service (internal
> service RequestPageCache) into a component:
>
> public class Menu {
>
> @Inject("RequestPageCache")
> RequestPageCache requestPageCache;
>
> public String getPageName() {
>
> ComponentResources pageResources= resources.getPage
> ().getComponentResources();
> String pageClassName= pageResources.getCompleteId();
> Page page= requestPageCache.getByClassName(pageClassName);
> return page.getName();
> }
> }
>
> so...while rendering the page with the menu component
>
> <div id="leftside">
> <div id="menu">
> <ul>
> <li>
> ${pageName}
> </li>
> </ul>
> </div>
> </div>
>
> a null pointer exception occures, because "requestPageCache" is null.
> What is getting wrong? Is RequestPageCache not injectable?
>
> What I want: I just try to get the page of the component. Then the
> menu component should highlight by providing a special css-class the
> corresponding menu item of the <ul><li>-list for the active page.
> Therefore the menu component must know the current page that is
> rendered. In Tapestry 3 is just call the method getPage of the
> component. Now every component has no parent class...
>
> While we are talking about injection: the docs are a little bit
> confusing:
>
> @Inject
> @Service("xxx") (which did not work with 5.0.3, because Service
> annotation does not exist)
>
> or
>
> @Inject("xxx")
>
> or
>
> @Inject( "service:xxx" ) (what kind of prefixes (service:) exists and
> what meaning have they?)
>
> sometimes:
> @Inject ("alias:request" )...is there somewhere a list with all
> objects that are able to be injected from tapestry-core?
>
> thanks for any help
>
> cheers
>
> Michael
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind
Professional Tapestry training, mentoring, support
and project work. http://howardlewisship.com
Re: T5: How to inject a service into a component?
Posted by Howard Lewis Ship <hl...@gmail.com>.
Sure beats abstract properties, though!
On 5/4/07, Howard Lewis Ship <hl...@gmail.com> wrote:
>
> Tapestry works by identifying the points at which a variable is read or
> updated and often replaces that with a method invocation that does something
> more complicated (such as persistent field values or component parameters).
>
> If the field is private, Tapestry is able to make the changes within a
> single class.
>
> If we supported non-private members, it gets a couple of orders of
> magnitude more complicated. You can no longer perform the instrumentation
> on a class-by-class basic; instead you have to identify every possible class
> and perform all the instrumentations at once. This is more like how APT or
> AspectJ works and isn't feasible for Tapestry, since by design, many of the
> instrumentations are only known about, or implementable, at runtime.
>
> On 5/4/07, Jesse Kuhnert <jk...@gmail.com> wrote:
> >
> > I hope that's not the only reason. ...The framework should be working
> > hard -
> > not the users. ;)
> >
> > On 5/4/07, Massimo Lusetti <ml...@gmail.com> wrote:
> > >
> > > On 5/4/07, Jesse Kuhnert <jk...@gmail.com> wrote:
> > >
> > > > I wonder why this is as well, it's happened at least a couple times
> > now
> > > -
> > > > at least enough that this idea may need to be re-evaluated. (I can
> > help
> > > if
> > > > it's just reflection stuff)
> > >
> > > This way the framework (inner javassist stuff) only need to 'scan' for
> > > private instances.
> > >
> > > --
> > > Massimo
> > > http://meridio.blogspot.com
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > > For additional commands, e-mail: users-help@tapestry.apache.org
> > >
> > >
> >
> >
> > --
> > Jesse Kuhnert
> > Tapestry/Dojo team member/developer
> >
> > Open source based consulting work centered around
> > dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com
> >
>
>
>
> --
> Howard M. Lewis Ship
> TWD Consulting, Inc.
> Independent J2EE / Open-Source Java Consultant
> Creator and PMC Chair, Apache Tapestry
> Creator, Apache HiveMind
>
> Professional Tapestry training, mentoring, support
> and project work. http://howardlewisship.com
>
--
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind
Professional Tapestry training, mentoring, support
and project work. http://howardlewisship.com
Re: T5: How to inject a service into a component?
Posted by Howard Lewis Ship <hl...@gmail.com>.
Tapestry works by identifying the points at which a variable is read or
updated and often replaces that with a method invocation that does something
more complicated (such as persistent field values or component parameters).
If the field is private, Tapestry is able to make the changes within a
single class.
If we supported non-private members, it gets a couple of orders of magnitude
more complicated. You can no longer perform the instrumentation on a
class-by-class basic; instead you have to identify every possible class and
perform all the instrumentations at once. This is more like how APT or
AspectJ works and isn't feasible for Tapestry, since by design, many of the
instrumentations are only known about, or implementable, at runtime.
On 5/4/07, Jesse Kuhnert <jk...@gmail.com> wrote:
>
> I hope that's not the only reason. ...The framework should be working hard
> -
> not the users. ;)
>
> On 5/4/07, Massimo Lusetti <ml...@gmail.com> wrote:
> >
> > On 5/4/07, Jesse Kuhnert <jk...@gmail.com> wrote:
> >
> > > I wonder why this is as well, it's happened at least a couple times
> now
> > -
> > > at least enough that this idea may need to be re-evaluated. (I can
> help
> > if
> > > it's just reflection stuff)
> >
> > This way the framework (inner javassist stuff) only need to 'scan' for
> > private instances.
> >
> > --
> > Massimo
> > http://meridio.blogspot.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
> --
> Jesse Kuhnert
> Tapestry/Dojo team member/developer
>
> Open source based consulting work centered around
> dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com
>
--
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind
Professional Tapestry training, mentoring, support
and project work. http://howardlewisship.com
Re: T5: How to inject a service into a component?
Posted by Jesse Kuhnert <jk...@gmail.com>.
I hope that's not the only reason. ...The framework should be working hard -
not the users. ;)
On 5/4/07, Massimo Lusetti <ml...@gmail.com> wrote:
>
> On 5/4/07, Jesse Kuhnert <jk...@gmail.com> wrote:
>
> > I wonder why this is as well, it's happened at least a couple times now
> -
> > at least enough that this idea may need to be re-evaluated. (I can help
> if
> > it's just reflection stuff)
>
> This way the framework (inner javassist stuff) only need to 'scan' for
> private instances.
>
> --
> Massimo
> http://meridio.blogspot.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Jesse Kuhnert
Tapestry/Dojo team member/developer
Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com
Re: T5: How to inject a service into a component?
Posted by Massimo Lusetti <ml...@gmail.com>.
On 5/4/07, Jesse Kuhnert <jk...@gmail.com> wrote:
> I wonder why this is as well, it's happened at least a couple times now -
> at least enough that this idea may need to be re-evaluated. (I can help if
> it's just reflection stuff)
This way the framework (inner javassist stuff) only need to 'scan' for
private instances.
--
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: How to inject a service into a component?
Posted by Jesse Kuhnert <jk...@gmail.com>.
I wonder why this is as well, it's happened at least a couple times now -
at least enough that this idea may need to be re-evaluated. (I can help if
it's just reflection stuff)
On 5/4/07, Michael Maier <mi...@vivai.de> wrote:
>
> ok, I solved... requestPageCache must be private...I don't know why
> the variable to be injected must be declared private but tapestry
> could log a warning, that the instance variable is not private and
> therefor it won't be injected...
> <snipped>
>
--
Jesse Kuhnert
Tapestry/Dojo team member/developer
Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com
Re: T5: How to inject a service into a component?
Posted by Michael Maier <mi...@vivai.de>.
ok, I solved... requestPageCache must be private...I don't know why
the variable to be injected must be declared private but tapestry
could log a warning, that the instance variable is not private and
therefor it won't be injected...
Am 04.05.2007 um 11:37 schrieb Michael Maier:
> @Inject("RequestPageCache")
> RequestPageCache requestPageCache;
cheers
Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
RE: T5: How to inject a service into a component?
Posted by Kristian Marinkovic <kr...@porsche.co.at>.
hi michael,
it should work with just @Inject. You can take a look at the
BeanEditForm component... it uses a bunch of @Injects.
(T5.0.4)
g,
kris
Michael Maier <mi...@vivai.de>
04.05.2007 11:37
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>
An
Tapestry users <us...@tapestry.apache.org>
Kopie
Thema
T5: How to inject a service into a component?
Hi List,
I'm trying to inject via @Inject annotation a service (internal
service RequestPageCache) into a component:
public class Menu {
@Inject("RequestPageCache")
RequestPageCache requestPageCache;
public String getPageName() {
ComponentResources pageResources= resources.getPage
().getComponentResources();
String pageClassName= pageResources.getCompleteId();
Page page= requestPageCache.getByClassName(pageClassName);
return page.getName();
}
}
so...while rendering the page with the menu component
<div id="leftside">
<div id="menu">
<ul>
<li>
${pageName}
</li>
</ul>
</div>
</div>
a null pointer exception occures, because "requestPageCache" is null.
What is getting wrong? Is RequestPageCache not injectable?
What I want: I just try to get the page of the component. Then the
menu component should highlight by providing a special css-class the
corresponding menu item of the <ul><li>-list for the active page.
Therefore the menu component must know the current page that is
rendered. In Tapestry 3 is just call the method getPage of the
component. Now every component has no parent class...
While we are talking about injection: the docs are a little bit
confusing:
@Inject
@Service("xxx") (which did not work with 5.0.3, because Service
annotation does not exist)
or
@Inject("xxx")
or
@Inject( "service:xxx" ) (what kind of prefixes (service:) exists and
what meaning have they?)
sometimes:
@Inject ("alias:request" )...is there somewhere a list with all
objects that are able to be injected from tapestry-core?
thanks for any help
cheers
Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org