You can easily be led to believe that CDI is the future and that managed beans will be consigned to the
scrapheap, yet when you look into it I wouldn't say that there are loads of big advantages right now.
The main problem I initially encountered when looking to move to CDI was that CDI has no view scope,
and all my beans were view scoped. I then found out that Seam 3 provided a view scope, but that there
were some terminal compatibility problems with Seam 3 and Weld 1.1 as packaged with Glassfish 3.1.
What I would strongly suggest looking at is Myfaces CDI extensions (aka Myfaces CODI) which can be
found here:
http://myfaces.apache.org/extensions/cdi/. This can be positioned similarly to Seam 3 in
that it provides some additional useful stuff, notably scopes. There's @ViewAccessScoped which has
alleviated all the frustrations I had with the limitations of the out of the box scopes provided with both
CDI, managed beans, and Seam 3, all in one go. It basically keeps a bean in scope until the first request
of a new view doesn't access it. This allows you to get rid of unwieldly view parameters, amongst other
things.
CODI provides a better thought out conversation scope, and conversation scope groups. You can @Inject
ejbs into converters and validators instead of using jndi lookup also. You need to root about a bit on the
wiki to find the documentation, but whilst not extensive at least there is some:
https://cwiki.apache.org/confluence/display/EXTCDI/JSF+Usage#JSFUsage-ViewAccessScope
One interesting point to note that without changing a single line of code, just adding the CODI jars to your
project will cause it to use CDI instead of managed beans because the existing annotations are intercepted.
It took a little while to figure out which jars to include, so if you can use
maven you'll be making life easy
for yourself.
Note that you do not have to be using the myfaces JSF implementation to take advantage of this, it works
fine with mojarra.
Regards,
Brendan.