users@glassfish.java.net

_at_Model versus _at_Named versus _at_ManagedBean

From: <glassfish_at_javadesktop.org>
Date: Fri, 10 Sep 2010 20:19:49 PDT

I am working up my first JSF 2.0 application under GF 3 and ran into this issue that is bugging me. There does not seem to be any definitive answer I can find on this and I want to follow best practices start to finish.

By experimentation and reading examples on the web I have found that I can create managed beans for my application by either using the annotations @java.faces.bean.ManagedBean, or by @javax.inject.Named, or by @javax.enterprise.inject.Model.

The JSF 2.0 books say to use @ManagedBean. The NetBeans template uses @Named. And then when I look into the CDI specification their JSF example uses @Model.

The same applies to using the bean, either @javax.inject.Inject, or JSF's @Resource.

Don't get me wrong I am happy they all seem to work. But what is the RIGHT one to use, i.e. "best practice?" For that matter what is the difference?
[Message sent by forum member 'alan94539']

http://forums.java.net/jive/thread.jspa?messageID=482397