You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by Manuel Chinea <ma...@gmail.com> on 2010/04/11 18:58:10 UTC
EJB 3.1 injection of a SessionBean in a click page
Hi,
is there a way to inject a SLSB in a click page using the @EJB annotation or
something like that?
Thnxs in advance
--
Manuel Chinea.
Re: EJB 3.1 injection of a SessionBean in a click page
Posted by Manuel Chinea <ma...@gmail.com>.
Hi Bob,
2010/4/14 Bob Schellink <sa...@gmail.com>
> Hi Manuel,
>
> Great work. I assume this was done with Glassfish 3?
>
Yes, glassfish v3 (build 74.2 i think, don't remember the exact build right
now)
> So I am correct in saying that as long as CDI created the Page it
> automatically injected EJB annotated services?
>
>
Yes. I tested this originally with a Page that had and annotated @EJB
attribute. Latter tested by making a Producer that created a POJO and a Page
with a @Inject of that POJO type. It worked.
>
> One thing I'm not sure of is this:
>
> * The jndi name under which the BeanManager can be found according to the
> CDI spec in a JEE6 app server
> public static final String CDI_BEANMANAGER_JNDILOOKUPNAME =
> "java:comp/BeanManager";
>
> I've found that certain containers doesn't use the 'java:' prefix for JNDI
> lookups. Do you have a reference where this name is specified in the spec?
>
>
I saw it in the jsr-299 spec (Chapter 11 -> 11.3. The BeanManager object). I
googled "javadoc BeanManager" and found this link to the javadoc:
http://www.jarvana.com/jarvana/view/javax/enterprise/cdi-api/1.0/cdi-api-1.0-javadoc.jar!/javax/enterprise/inject/spi/BeanManager.html
About the java: prefix, i saw in the struts2-plugin, there is another
prefix, don“t remember it right now.
As i mentioned before, so far i've just done a couple of "Hello World" tests
of this. I'll like you to give it a try and give me some feedback on it.
Back to work, see ya!
regards
kind regards
>
> bob
>
>
>
> On 14/04/2010 22:01, Manuel Chinea wrote:
>
>> Hi,
>>
>> I a have managed to do a cdi- based click servlet. Alpha quality code
>> yet (no error or edge cases handling, no javadoc), but it creates the
>> Page objects through the cdi api.
>>
>> Here is the JIRA issue https://issues.apache.org/jira/browse/CLK-656
>> with some instructions on the use of the Servlet.
>>
>> So far i have tested injecting EJB (with the @EJB annotation) and Plain
>> POJOs using Producers.
>>
>> regards
>>
>> 2010/4/12 Bob Schellink <sabob1@gmail.com <ma...@gmail.com>>
>>
>>
>> On 12/04/2010 23:19, Manuel Chinea wrote:
>>
>>
>> Ok, i meant more of a project-specific Page, like MyPage, not the
>> Framework specific Page.
>>
>>
>>
>> Ah nods, I meant an application specific page as well. You can
>> certainly do this in a BasePage or BorderPage, however the reason
>> I'm suggesting you don't, is your BasePage can grow quite large as
>> the number of services grow. We've found that large super pages can
>> be difficult to digest by new developers working on our application.
>>
>> However since everybody's needs is different a super page exposing
>> services might not pose a problem in your case. And if down the road
>> it does, you can easily refactor the services into a separate
>> Service Locator or Service Factory class.
>>
>>
>>
>> Ah, that is very interesting. I totally forgot about the
>> ClickServlet!.
>> I'll take a look on that option. That way i'll learn a little
>> bit more
>> of Apache Click in the process! ;).
>>
>>
>> Agreed :)
>>
>> I'm also hoping a future release of Click could expose a page
>> creation service interface so the ClickServlet doesn't have to be
>> subclassed.
>>
>> kind regards
>>
>> bob
>>
>>
>> --
>> Manuel Chinea.
>>
>
> --
Manuel Chinea.
Re: EJB 3.1 injection of a SessionBean in a click page
Posted by Bob Schellink <sa...@gmail.com>.
Hi Manuel,
Great work. I assume this was done with Glassfish 3?
So I am correct in saying that as long as CDI created the Page it automatically injected EJB
annotated services?
One thing I'm not sure of is this:
* The jndi name under which the BeanManager can be found according to the CDI spec in a JEE6 app
server
public static final String CDI_BEANMANAGER_JNDILOOKUPNAME = "java:comp/BeanManager";
I've found that certain containers doesn't use the 'java:' prefix for JNDI lookups. Do you have a
reference where this name is specified in the spec?
kind regards
bob
On 14/04/2010 22:01, Manuel Chinea wrote:
> Hi,
>
> I a have managed to do a cdi- based click servlet. Alpha quality code
> yet (no error or edge cases handling, no javadoc), but it creates the
> Page objects through the cdi api.
>
> Here is the JIRA issue https://issues.apache.org/jira/browse/CLK-656
> with some instructions on the use of the Servlet.
>
> So far i have tested injecting EJB (with the @EJB annotation) and Plain
> POJOs using Producers.
>
> regards
>
> 2010/4/12 Bob Schellink <sabob1@gmail.com <ma...@gmail.com>>
>
> On 12/04/2010 23:19, Manuel Chinea wrote:
>
>
> Ok, i meant more of a project-specific Page, like MyPage, not the
> Framework specific Page.
>
>
>
> Ah nods, I meant an application specific page as well. You can
> certainly do this in a BasePage or BorderPage, however the reason
> I'm suggesting you don't, is your BasePage can grow quite large as
> the number of services grow. We've found that large super pages can
> be difficult to digest by new developers working on our application.
>
> However since everybody's needs is different a super page exposing
> services might not pose a problem in your case. And if down the road
> it does, you can easily refactor the services into a separate
> Service Locator or Service Factory class.
>
>
>
> Ah, that is very interesting. I totally forgot about the
> ClickServlet!.
> I'll take a look on that option. That way i'll learn a little
> bit more
> of Apache Click in the process! ;).
>
>
> Agreed :)
>
> I'm also hoping a future release of Click could expose a page
> creation service interface so the ClickServlet doesn't have to be
> subclassed.
>
> kind regards
>
> bob
>
>
> --
> Manuel Chinea.
Re: EJB 3.1 injection of a SessionBean in a click page
Posted by Manuel Chinea <ma...@gmail.com>.
Hi,
I a have managed to do a cdi- based click servlet. Alpha quality code yet
(no error or edge cases handling, no javadoc), but it creates the Page
objects through the cdi api.
Here is the JIRA issue https://issues.apache.org/jira/browse/CLK-656 with
some instructions on the use of the Servlet.
So far i have tested injecting EJB (with the @EJB annotation) and Plain
POJOs using Producers.
regards
2010/4/12 Bob Schellink <sa...@gmail.com>
> On 12/04/2010 23:19, Manuel Chinea wrote:
>
>>
>> Ok, i meant more of a project-specific Page, like MyPage, not the
>> Framework specific Page.
>>
>
>
> Ah nods, I meant an application specific page as well. You can certainly do
> this in a BasePage or BorderPage, however the reason I'm suggesting you
> don't, is your BasePage can grow quite large as the number of services grow.
> We've found that large super pages can be difficult to digest by new
> developers working on our application.
>
> However since everybody's needs is different a super page exposing services
> might not pose a problem in your case. And if down the road it does, you can
> easily refactor the services into a separate Service Locator or Service
> Factory class.
>
>
>
> Ah, that is very interesting. I totally forgot about the ClickServlet!.
>> I'll take a look on that option. That way i'll learn a little bit more
>> of Apache Click in the process! ;).
>>
>
> Agreed :)
>
> I'm also hoping a future release of Click could expose a page creation
> service interface so the ClickServlet doesn't have to be subclassed.
>
> kind regards
>
> bob
>
--
Manuel Chinea.
Re: EJB 3.1 injection of a SessionBean in a click page
Posted by Bob Schellink <sa...@gmail.com>.
On 12/04/2010 23:19, Manuel Chinea wrote:
>
> Ok, i meant more of a project-specific Page, like MyPage, not the
> Framework specific Page.
Ah nods, I meant an application specific page as well. You can certainly do this in a BasePage or
BorderPage, however the reason I'm suggesting you don't, is your BasePage can grow quite large as
the number of services grow. We've found that large super pages can be difficult to digest by new
developers working on our application.
However since everybody's needs is different a super page exposing services might not pose a problem
in your case. And if down the road it does, you can easily refactor the services into a separate
Service Locator or Service Factory class.
> Ah, that is very interesting. I totally forgot about the ClickServlet!.
> I'll take a look on that option. That way i'll learn a little bit more
> of Apache Click in the process! ;).
Agreed :)
I'm also hoping a future release of Click could expose a page creation service interface so the
ClickServlet doesn't have to be subclassed.
kind regards
bob
Re: EJB 3.1 injection of a SessionBean in a click page
Posted by Manuel Chinea <ma...@gmail.com>.
Hi Bob,
2010/4/12 Bob Schellink <sa...@gmail.com>
> On 12/04/2010 11:00, Manuel Chinea wrote:
>
> I guess a simple way to do this is doing the ctx.lookup of the SLSB.
>> Could/should it be done in a custom ConfigService or a TypeConverter
>> class in click? or better in a Superclass?
>>
>
>
> ctx.lookup has been the approach used in EJB containers this far.
>
> I wouldn't use a superclass for this though. While its simple, the Page is
> not really the place to manage service lookup logic.
>
Ok, i meant more of a project-specific Page, like MyPage, not the Framework
specific Page.
>
> I'd recommend a ServiceFactory or ServiceLocator pattern, unless J2EE 6
> provides a way to inject services into POJOs directly.
>
Yeap, i saw this as a Plan B, combined with my project-specific Superclass
MyPage.
>
> Another approach is to subclass ClickServlet, override newPageInstance
> which passes in the pageClass to create, scan for @EJB annotated services
> and inject them manually. The SpringClickServlet does something similar, so
> have a look for some inspiration.
>
Ah, that is very interesting. I totally forgot about the ClickServlet!. I'll
take a look on that option. That way i'll learn a little bit more of Apache
Click in the process! ;).
>
> kind regards
>
> bob
>
Thnxs a lot!
--
Manuel Chinea.
Re: EJB 3.1 injection of a SessionBean in a click page
Posted by Bob Schellink <sa...@gmail.com>.
On 12/04/2010 11:00, Manuel Chinea wrote:
> I guess a simple way to do this is doing the ctx.lookup of the SLSB.
> Could/should it be done in a custom ConfigService or a TypeConverter
> class in click? or better in a Superclass?
ctx.lookup has been the approach used in EJB containers this far.
I wouldn't use a superclass for this though. While its simple, the Page is not really the place to
manage service lookup logic.
I'd recommend a ServiceFactory or ServiceLocator pattern, unless J2EE 6 provides a way to inject
services into POJOs directly.
Another approach is to subclass ClickServlet, override newPageInstance which passes in the pageClass
to create, scan for @EJB annotated services and inject them manually. The SpringClickServlet does
something similar, so have a look for some inspiration.
kind regards
bob
Re: EJB 3.1 injection of a SessionBean in a click page
Posted by Manuel Chinea <ma...@gmail.com>.
Hi Bob,
As far as i have been able to read the cdi specs (an hour this afternoon),
it looks like the managed objects of the jee container get this cdi-magic
out of the box (by managed objects i mean: servlets and jsf on the web side
of things, all the types of ejb from the ejb side). I have found some
information of other web frameworks starting on doing cdi-injection (struts2
and wicket). The Seam framework has also some intregration with wicket.
As for the EJB into a POJO injection, i am not sure. I'll keep on reading.
Glassfish v3 supports jee6, i am already using it in my laptop right now.
I guess a simple way to do this is doing the ctx.lookup of the SLSB.
Could/should it be done in a custom ConfigService or a TypeConverter class
in click? or better in a Superclass?
2010/4/11 Bob Schellink <sa...@gmail.com>
> Hi Manuel,
>
> Good question. I'm a bit rusty on the latest EJB development, but I'd
> imagine the only way to automatically inject an EJB is if the target class
> was managed by the EJB container. Click Pages are not managed by the EJB
> container so I'd guess you won't be able to do that out-of-the-box.
>
> Changing the question a little. Is it possible to inject EJB into a POJO?
> If it is then it will be possible with Click Pages as well. There is the
> spec: Contexts and Dependency Injection (JSR 299) which from the looks of it
> addresses this problem. I'm not sure which container supports this yet
> though.
>
> kind regards
>
> bob
>
>
>
> On 12/04/2010 02:58, Manuel Chinea wrote:
>
>> Hi,
>>
>> is there a way to inject a SLSB in a click page using the @EJB
>> annotation or something like that?
>>
>> Thnxs in advance
>>
>> --
>> Manuel Chinea.
>>
>
>
regards
--
Manuel Chinea.
Re: EJB 3.1 injection of a SessionBean in a click page
Posted by Bob Schellink <sa...@gmail.com>.
Hi Manuel,
Good question. I'm a bit rusty on the latest EJB development, but I'd imagine the only way to
automatically inject an EJB is if the target class was managed by the EJB container. Click Pages are
not managed by the EJB container so I'd guess you won't be able to do that out-of-the-box.
Changing the question a little. Is it possible to inject EJB into a POJO? If it is then it will be
possible with Click Pages as well. There is the spec: Contexts and Dependency Injection (JSR 299)
which from the looks of it addresses this problem. I'm not sure which container supports this yet
though.
kind regards
bob
On 12/04/2010 02:58, Manuel Chinea wrote:
> Hi,
>
> is there a way to inject a SLSB in a click page using the @EJB
> annotation or something like that?
>
> Thnxs in advance
>
> --
> Manuel Chinea.