Search |
||
WebBeans in Glassfish v3Posted by cayhorstmann on July 5, 2009 at 9:39 PM PDT
As I am updating my share of chapters in the Core JavaServer Faces book (with the hard parts fortunately being tackled by my coauthor, David Geary), I started playing with WebBeans, erm, Java Contexts and Dependency Injection. I'll keep calling it WebBeans—the alternative JavaCandi is more than I can take. There are two features that are crucial for JSF users: Conversation scope and access to stateful session beans from JSF pages. (Seam users know all about this and can skip this blog.)
I have been using Glassfish for most of my test programs, mostly because I am used to it. But today, as I did some experiments with JBoss, I found another reason to like Glassfish—it boots a lot faster. (I remember a rather dismal Java One session with Jerome Dochez a couple of years ago where he demoed the embryonic Glassfish v3 and how it was wonderfully modular, and I thought “Oh boy, Second System Syndrome”. Well, I was wrong, and Glassfish v3 is wonderfully fast.) The current Glassfish v3 Preview has some support for WebBeans. As of today, it contains a 2-month old version of WebBeans and a more recent WebBeans integration module (look for Glassfish JCDI in the update tool). I got my first trivial app to work after paying attention to these points:
Then simply replace Of course, that's just another way of achieving what you can already do with JSF 2.0. For something strictly better, turn to conversation scope. In JSF, you have the uncomfortable choice between request scope (which is too short) and session scope (which is too long). JSF 2.0 gives us view scope and a flash object, neither of which is all that helpful in general. Conversation scope is what you want. You turn it on when you want to start a sequence of interactions with the user, then turn it off when that interaction has finished. The user can open two browser tabs with different conversations.
It's easy with WebBeans, and it works with the current Glassfish v3. Change
private @Current Conversation conversation; and calls conversation.begin(); and conversation.end(); into suitable action methods. The life of the bean is extended from request
to conversation scope when you call Perhaps this should have been a feature of JSF 2.0, but I take it any way I can get it. The other key feature is the ability to skip managed beans altogether and to invoke stateful session beans from your JSF pages. This does not seem to work in the current Glassfish, which is too bad. I get a warning INFO: Web Beans 1.0.0.PREVIEW1 INFO: Transactional services not available. Transactional observers will be invoked synchronously. INFO: EJB services not available. Session beans will be simple beans, injection into non-contextual EJBs, injection of @EJB in simple beans, injection of Java EE resources and JMS resources will not be available. INFO: JPA services not available. Injection of @PersistenceContext will not occur. Entity beans will be discovered as simple beans. INFO: @Resource injection not available. That's when I installed JBoss 5.1.0GA. Here are a few things I learned:
»
Comments
Comments are listed in date ascending order (oldest first)
Submitted by rogerk on Mon, 2009-07-06 09:36.
Hello Cay -
We have not implemented Web Beans EJB support in GlassFish yet. We are working on that. Glad to hear that you were able to use the non EJB portion.
Submitted by pmuir on Tue, 2009-07-28 12:12.
Whilst 299 only specifies an EE environment, Web Beans will work in SE (we have a simple example using Swing), and can degrade gracefully from full EE (with transactional services, EJB support, JPA support etc.) down to Servlet (Tomcat) only and so on.
You see those messaages because, as Roger says, Web Beans in GlassFish doesn't currently support EE services, only Servlet. As you correctly identify, JBoss AS does support EE services for Web Beans. I know the GlassFish guys are working hard on adding the EE support :-)
BTW I've not had any problems with JBoss 5.1 and the Eclipse support, but I use JBoss Tools 3.1 M2 (http://jboss.org/tools) which bundles an update IIRC to allow JBoss 5.1 support.
|
||
|