webtier@glassfish.java.net

Re: [webtier] using EJBs inside JSF pages - is it possible ?

From: Felipe Gaścho <fgaucho_at_gmail.com>
Date: Mon, 14 Dec 2009 20:45:13 +0100

great !

I will try asap..

I have a JPA backend + a RESTful web-service.. now I am adding a JSF
frontend and it would be wonderful to inject the persistence beans
directly in the pages instead of having a lot of managedbeans just to
proxy between layers.........

On Mon, Dec 14, 2009 at 12:33 PM, <webtier_at_javadesktop.org> wrote:
> Yes, it is! You can do it through CDI.
>
> // Your EJB -------------------------------------
> @Named("myEJB")
> @Stateful
> @SessionScoped
> public class MyEJB {
>  public void aMethod() {
>    // do something interesting here...
>  }
> }
> // ------------------------------------------------
>
> <!-- Your JSF view ----------------------------- -->
> <html xmlns:h="...">
>  <h:body>
>    <h:form>
>      <!-- Another things in your form -->
>      <h:commandButton value="Do something..." action="#{myEJB.aMethod}" />
>    </h:form>
>  </h:body>
> </html>
> <!-- ---------------------------------------------- -->
>  You still need an empty "beans.xml" in your WEB-INF, in case of a pure WebApp, or both WEB-INF and META-INF, if your project a full EnterpriseApp.
>
> Maybe you'll need to fix something in this code but basically it works. For more information you can look for JCDI (or just CDI) or WebBeans on google. Try to give a look on the last entries in Gavin King's and Adam Bien's blog.
> You'll find a lot of information about it specially on Gavin King's blog.
> [Message sent by forum member 'yellowbike' ]
>
> http://forums.java.net/jive/thread.jspa?messageID=376371
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: webtier-help_at_glassfish.dev.java.net
>
>



-- 
------------------------------------------
   Felipe Gaścho
   10+ Java Programmer
   CEJUG Senior Advisor