You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Denis Souza <de...@camerum.com.br> on 2007/01/20 20:48:27 UTC

RE: Inject EJB 3 into Tapestry 4 page

I sent an e-mail a few weeks ago asking about injecting EJBs in tapestry
pages. I found a way to do it, so I'm sharing it with the list since there
were other people interested. It's really very easy.

All you have to do is create a hivemind object provider that will supply you
with the information you want. Something like this:

public class EJBObjectProvider implements ObjectProvider {

public Object provideObject(Module module, Class propertyType, String
locator, Location location) {
	return jndiLookup(locator);
}
}

This is a bit simplified. In my case I use a caching mechanism to save on
jndi lookups.

Then you have to tell hivemind about your new object provider by adding to
you hivemodule.xml:

<service-point id="EJBObjectProvider"
interface="org.apache.hivemind.service.ObjectProvider">
  <invoke-factory>
    <construct class="EJBObjectProvider">
      <set-object property="applicationStateManager"
value="infrastructure:applicationStateManager"/>
    </construct>
   </invoke-factory>
</service-point>

I'm also injecting an application state manager for my own logic, but you
can use anything here. Also add the following:

<contribution configuration-id="hivemind.ObjectProviders">
   <provider prefix="ejb" service-id="EJBObjectProvider"/>
</contribution>

That's it. Now you can inject any EJBs by simply adding something like this
in your page or component:

@InjectObject("ejb:myBeanJndiName")
public abstract MyBean getMyBean();

I hope it was helpful. I really don't know that much about hivemind use so
it took me some tapestry source code exploring to figure this one out. I
welcome any suggestions on how to improve this.

Cheers,
Denis

-----Original Message-----
From: Bastian Voigt [mailto:post@bastian-voigt.de] 
Sent: quarta-feira, 20 de dezembro de 2006 13:40
To: Tapestry users
Cc: Denis Souza
Subject: Re: Inject EJB 3 into Tapestry 4 page

Hi,
did you find out anything? I am having the same problem.

Regards
Bastian Voigt

On Monday 18 December 2006 21:44, Denis Souza wrote:
> That's just about what I need, but for EJB 3. This service seems to assume
> EJB 2.x since it requires a home interface.

---------------------------------------------------------------------
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: Inject EJB 3 into Tapestry 4 page

Posted by Renat Zubairov <re...@gmail.com>.
Hi

Sorry for Off topic, but that's amazing how simple the solution is, I
can't stop wondering how a small group of people (read Hivemind and
Tapestry developers) and especially Howard were so smart to create
such a beautiful, simple and flexible solution, where such problems
like integration with EJB3 can be solved so simple and concise.
BTW thank you Denis for the solution, I'll use it in my code as well.

Renat


On 20/01/07, Denis Souza <de...@camerum.com.br> wrote:
> I sent an e-mail a few weeks ago asking about injecting EJBs in tapestry
> pages. I found a way to do it, so I'm sharing it with the list since there
> were other people interested. It's really very easy.
>
> All you have to do is create a hivemind object provider that will supply you
> with the information you want. Something like this:
>
> public class EJBObjectProvider implements ObjectProvider {
>
> public Object provideObject(Module module, Class propertyType, String
> locator, Location location) {
>         return jndiLookup(locator);
> }
> }
>
> This is a bit simplified. In my case I use a caching mechanism to save on
> jndi lookups.
>
> Then you have to tell hivemind about your new object provider by adding to
> you hivemodule.xml:
>
> <service-point id="EJBObjectProvider"
> interface="org.apache.hivemind.service.ObjectProvider">
>   <invoke-factory>
>     <construct class="EJBObjectProvider">
>       <set-object property="applicationStateManager"
> value="infrastructure:applicationStateManager"/>
>     </construct>
>    </invoke-factory>
> </service-point>
>
> I'm also injecting an application state manager for my own logic, but you
> can use anything here. Also add the following:
>
> <contribution configuration-id="hivemind.ObjectProviders">
>    <provider prefix="ejb" service-id="EJBObjectProvider"/>
> </contribution>
>
> That's it. Now you can inject any EJBs by simply adding something like this
> in your page or component:
>
> @InjectObject("ejb:myBeanJndiName")
> public abstract MyBean getMyBean();
>
> I hope it was helpful. I really don't know that much about hivemind use so
> it took me some tapestry source code exploring to figure this one out. I
> welcome any suggestions on how to improve this.
>
> Cheers,
> Denis
>
> -----Original Message-----
> From: Bastian Voigt [mailto:post@bastian-voigt.de]
> Sent: quarta-feira, 20 de dezembro de 2006 13:40
> To: Tapestry users
> Cc: Denis Souza
> Subject: Re: Inject EJB 3 into Tapestry 4 page
>
> Hi,
> did you find out anything? I am having the same problem.
>
> Regards
> Bastian Voigt
>
> On Monday 18 December 2006 21:44, Denis Souza wrote:
> > That's just about what I need, but for EJB 3. This service seems to assume
> > EJB 2.x since it requires a home interface.
>
> ---------------------------------------------------------------------
> 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
>
>


-- 
Best regards,
Renat Zubairov

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