Jeremy,<br><br>Thanks for your excellent reply. I&#39;m excited because I see a common thread emerging in our exchange and, with some clarifications on my part, I think we can arrive at a compatible message. Let me state the message, then get into the inline responses.<br>

<br>The JSF EG is in the business of creating a UI component model specification. That&#39;s complex enough on it&#39;s own. A programming model is equally complex and better solved by existing solutions. (JSR-299 took 3 years to work it out and Spring has been around twice that long).<br>
<br>If the developer wants to target a native Java EE technology stack, we should consider recommending platform managed beans (@javax.annotation.ManagedBean) with CDI services. If the developer&#39;s scope is broader, then we could suggest for them to consider alternative bean containers such as Spring. It&#39;s even possible to recommend the use of @javax.annotation.ManagedBean with @javax.inject.Inject to have a bean which is portable to both Java EE and Spring, likely the ideal recommendation for setting a common ground.<br>
<br>Hopefully we can all agree that it&#39;s time to look past the rudimentary JSF managed bean facility. I don&#39;t think we do anyone a service by showing them the @javax.faces.ManagedBean in examples because it&#39;s just not going to stand up to the long-term challenges the developer is going to face.<br>

<br>I&#39;ll now jump inline to provide clarifications of my earlier statements to help support this neutral position.<br><br><div class="gmail_quote">
On Fri, Dec 18, 2009 at 9:08 PM, Jeremy Grelle <span dir="ltr">&lt;<a href="mailto:Jeremy.Grelle@springsource.com" target="_blank">Jeremy.Grelle@springsource.com</a>&gt;</span> wrote:<br><div> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
First off, I agree that the ultimate goal of pointing users away from the JSF-managed bean model is a good thing.</blockquote><div><br>Great!<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
That said, we (myself and Keith along with the rest of the Spring team whom we represent) have our reservations about CDI.  So while I agree that the ultimate goal is a good one, I just want to be clear that I am slightly wary of this getting turned around and becoming a public statement of, &quot;The JSF EG thinks you should use CDI.&quot;  If some of the members of the EG want to individually make that push, that&#39;s their right, just as it is ours to say we don&#39;t see a great benefit to choosing CDI over Spring. What I would really like to see is us figuring out the most possible common ground between CDI and Spring when showing examples that are alternative to the JSF managed bean facility.<br>
</blockquote><div><br>Absolutely. I think if the goal is to demonstrate a common ground solution, then a @javax.annotation.ManagedBean with @javax.inject.Inject is the way to go. If the presentation or demonstration has either a more Java EE-centric theme or a more Spring-centric theme, then naturally the recommendation can swing to the respective side.<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
I really want to make it clear that we don&#39;t see it as an &quot;us vs. them&quot; thing when talking about Spring and Java EE on the whole.</blockquote><div><br>Great! And neither do I. I think that we all work hard to offer developers good strong choices and I want to continue to learn from each other. The representatives from the various JSF component libraries set a nice example for how collaboration, rather than contests, strengthen the whole ecosystem.<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Spring has always provided first-class integration with a wide range of the individual parts of EE, and we continue to do so with EE 6 beyond just JSF 2 as evidenced by our support of specs like JSR-330, JPA 2, Bean Validation, javax.annotation.ManagedBean, etc. in the recently finalized Spring 3.0.</blockquote>
<div><br>What&#39;s important here is it respects the developer&#39;s time spent learning this programming model and we can leverage that common thread in the case when we want to show compatible programming model in a JSF 2 example.<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">The major difference being that we enable the use of these pieces in a completely modular and portable way that is just as powerful in a lightweight servlet container like Tomcat as it is in a full-blown commercial app server like WebSphere or WebLogic.  The benefits are evidenced by the fact that you can easily use many of these EE 6 pieces *today* with Spring 3.0 even in a container like WebSphere 6.1 that is still quite widely deployed and is only J2EE 1.4 compliant.<br>
</blockquote><div><br>The point you make here is one of the driving forces for Weld to provide the CDI environment for a Servlet Container. We also recognize that you sometimes have to cater to what is out there, and to provide lightweight solutions. My hope is that Java EE will continue to become more modular, but the Web Profile is certainly a step in that direction.<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

I&#39;m getting off-topic, but I just want to make the point that we are not anti-EE 6.<br></blockquote><div><br>Great! And I can share with you personally that when I recommend Java EE 6, it&#39;s because I see the potential in that platform, not because I&#39;m anti-Spring.<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><br>
&gt; When JSF was created, no other facility was available for defining contextual managed beans. As of Java EE 6, there is now a platform-wide definition of a managed bean.<br>
<br>
</div>I assume you mean javax.annotation.ManagedBean, right?  As I mentioned, we do support this in Spring 3.0.  I believe this, as well as the other shared annotations such as @Resource, @PersistenceContext, @Inject, etc. could be our best common ground to use when showing JSF 2 examples.<br>
</blockquote><div><br>Yes, @javax.annotation.ManagedBean. Excellent. I&#39;m excited we&#39;ve been able to find this common groud.<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


<div><br>
&gt; With the services of CDI, there is a way to discover, produce, scope, inject, name and override beans. All of a sudden, the injection facility, and limited number of services in the JSF managed bean facility looks rudimentary in comparison. And the reality is, before CDI, most developers likely used an alternative bean container anyway (probably Spring) to define managed beans. So the JSF managed bean facility has been falling out of favor for a long time.<br>


<br>
</div>Right, but are you saying we should all tell developers to use CDI instead of Spring now even if they are already happily using Spring?</blockquote><div><br>Not at all. I didn&#39;t mean to imply that developers should drop a solution they are happy with. As I said, many JSF 2 developers probably already have Spring in there.<br>
<br> What I&#39;m advocating is for JSF to step away from solving the managed bean problem, and for us to downplay the existing facility. JSF once had a responsbility to provide a managed bean container or else it wouldn&#39;t have worked in the Java EE platform. It needed to provide something so that it could be shipped with Java EE. Now, the managed bean spec and the CDI services is present to close that gap, relieving JSF of this responsibility.<br>
<br>So, when the context of a tutorial is the native Java EE platform, it&#39;s appropriate to show @javax.annotation.ManagedBean (with CDI) over the JSF managed bean facility. If the tutorial has a broader scope, then any backend container (Spring included) is certainly appropriate to demonstrate/recommend.<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I just don&#39;t see CDI being a clearly better alternative to Spring (in fact, I see the opposite, but I freely admit to being biased in that regard), and I don&#39;t know that we should have an opinion either way collectively as an EG. Again, individual opinions will vary as to which one to choose, but as a group it seems we should generally remain agnostic, especially if our overall goal is to get as many people as possible to be successful with JSF 2.<br>
</blockquote><div><br>+1 to not having to establish a collective opinion, other than to say it is not JSF managed beans.<br> 
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div><br>
&gt; But there is a more serious problem with continuing to recommend the use of the JSF managed bean facility. The injections do not take the scope of the injected bean into consideration. That means, you cannot inject a request-scoped bean into a session-scoped bean without causing the request-scoped bean to become a session-scoped bean through attachment. This is a very typical occurance with having managed beans in a web application. CDI not only keeps beans in different scopes loosely coupled, it hides the scope at the injection point.<br>


<br>
</div>I&#39;d just like to point out again for the sake of contrast that Spring 3.0 supports the same sort of approach quite well.  We of course supported this previously with our &quot;scoped-proxy&quot; feature since back in Spring 2.0, but it had to be configured per-bean and was thus only slightly less annoying than configuring JSF managed beans.  JSF was a major part of the use case for making it work &quot;by default&quot; with annotation-based configuration without having to do extra work.<br>
</blockquote><div><br>Yep, which backs up my statement that the JSF managed bean facility simply isn&#39;t cutting it anymore.<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


<div><br>
&gt; But I won&#39;t be able to use CDI in a Servlet Container, right?<br>
&gt;<br>
&gt; Not true. The CDI reference implementation (Weld) provides a single extension JAR (weld-servlet.jar) that you drop into your web application archive and you get a full CDI environment (you just don&#39;t get EJBs, but that&#39;s to be expected).<br>


<br>
</div>And by proxy you also don&#39;t get declarative transaction support, correct?  To me, that&#39;s an immediate show-stopper for any non-trivial application vs. what you get with Spring in a servlet container.<br></blockquote>
<div><br>Touche. I agree that a gap was left behind. The @TransactionAttribute annotation (in addition to some other EJB features) should have been allowed on platform managed beans. We plan to support this in Weld as a prototype for a revision of the platform. I won&#39;t deny that there is still work to be done in making the Java EE programming model truly excellent. But we can all improve, right?<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><br>
&gt; Isn&#39;t CDI just a Red Hat thing?<br>
&gt;<br>
&gt; Of course not. We should all be behind CDI. As the spec lead, Red Hat worked very hard to define a set of services for Java EE managed beans that would make the development of enterprise applications simpler. That&#39;s exactly the type of effort we all put in for the JSF 2 specification. (JSF 2 was forged by all of us collectively. CDI has the same story). So CDI is your technology, one that you can use in Java EE 6 or even outside of it. There is no reason to back away from it.<br>


<br>
</div>With all due respect, I still fail to see why we should *all* be behind CDI.<br></blockquote><div><br>Let me clarify the context here. When I used the term *all* here, I was thinking in the context of folks advocating the native Java EE platform, not all of the JSF EG, per se. If you are presenting on JSF 2 running in the context of native Java EE 6, you should be prefering CDI beans over the @javax.faces.ManagedBean without hesitation. As I said before, if you are presenting a broader view, then certainly consider any and all available backends and choose one based on merit.<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><br>
&gt; Perhaps a lot of the heated debating over dependency injection turned you off, but that heated debate really made the whole platform better because EG members, like us, talked and worked things out in the end.<br>
<br>
</div>Actually, what turns me off is that what we ended up with seems to only be partially worked out and is still a bit of a mess, to be perfectly blunt.  I&#39;ll elaborate more on that in my discussion of the examples below.<br>


<div><br>
&gt; @ManagedBean<br>
&gt; @RequestScoped<br>
&gt; public class BlogEditor {<br>
&gt;    @ManagedProperty(&quot;#{blogDao}&quot;) BlogDao blogDao;<br>
&gt;    // getters and setters required<br>
&gt; }<br>
<br>
</div>First off, I assume these (including @ManagedBean) are all from the javax.faces.bean set of annotations.</blockquote><div><br>Yes.<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Agreed, in this particular example, I would not recommend this approach.  What about @ViewScoped though?  That&#39;s one of the more useful pieces of JSF 2 in my opinion.  I don&#39;t believe there is an out-of-the-box CDI-equivalent, right?  I would assume it&#39;s not hard to implement a custom @ViewScoped that CDI would recognize?<br>
</blockquote><div><br>There isn&#39;t a CDI equivalent of @ViewScoped in the CDI spec, but Weld/Seam will be providing a portable extension, hopefully getting weaved back into a revision of the spec. We shouldn&#39;t have to revert to @javax.faces.ManagedBean just to get this feature.<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div><br>
&gt; We want to show them:<br>
&gt;<br>
&gt; @Named<br>
&gt; @RequestScoped<br>
&gt; public class BlogEditor {<br>
&gt;    @Inject BlogDao blogDao;<br>
&gt; }<br>
<br>
</div>So first of all, I think it would be great if we&#39;d ended up with something like the above that would &quot;just work&quot; in both CDI and Spring.  But we didn&#39;t.  We do actually support the use of @Named as a class-level annotation like this in Spring 3.0.  But I&#39;m curious, why in CDI do you recommend using @Named vs. javax.annotation.ManagedBean?  It seems to me like @ManagedBean has more clearly defined semantics at the class-level.<br>
</blockquote><div><br>I actually share this view with you, but I didn&#39;t have the ability to influence an alignment. As it turns out, @Named is a synonym for @ManagedBean, so we could recommend the latter in our common ground scenario.<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
Then we&#39;re back to the problem of the scopes.  We of course support various scope annotations in Spring, and support something equivalent to your above example, but don&#39;t specifically support the CDI scope annotations.  What really has me a bit confused is why the CDI scopes don&#39;t use @Scope from JSR-330 and instead use the JSR-299-specific @NormalScope.  The JSF scopes don&#39;t either, for that matter, but I assume that&#39;s because 330 was finalized well after.  See, this is what I mean by it being a bit of a mess.  We&#39;ve got some JSF-specific scopes, we&#39;ve got CDI-specific scopes, we&#39;ve got Spring-specific scopes, etc.  Spring can and will ultimately support the equivalent of all of the useful ones (including @ConversationScoped in the near future...I really wish we could have just relied on JSF or CDI for that), but it sadly seems like we ended up with more fragmentation rather than less.<br>
</blockquote><div><br>I&#39;ll admit that I don&#39;t know the story behind the choice to not align the scope annotations. And already we are hearing from developers that having the javax.faces.* stuff in there is adding to the confusion. That&#39;s why, to start, we need to get that stuff deprecated. Then, I think, we should figure out how to get the number of duplicate scopes down to one. I encourage you guys to pursue this goal over on the JSR-299 EG. The only way this is going to get resolved is if communication happens. We can&#39;t really solve that problem here.<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
So in the above example, we at least have @Named and @Inject as commonly supported things.  I really wish there were one common, complete and portable set of scope annotations we could support in Spring, but there isn&#39;t.<br>
</blockquote><div><br>The one consolation is that the semantics are exactly the same. A scope is a scope and it&#39;s defined on the bean class. So we have to fudge this around for now, but again, as long as we are staying away from @javax.faces we are heading in the right direction.<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div><br>
&gt; I&#39;m asking you to consider my request to get behind CDI.<br>
<br>
</div>I&#39;m perfectly fine with a world where CDI and Spring co-exist peacefully.</blockquote><div><br>+1<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Despite my own misgivings about CDI, I acknowledge that it appeals to some.  The goal of moving away from the JSF managed bean is a good one.</blockquote><div><br>+1<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
But as the collective EG whose goal is to see as much adoption as possible of JSF 2, and given the corporate realities of how soon most people are going to be using an EE 6 container, I don&#39;t see how we can be asked to promote it as *the* choice of the EG.<br>
</blockquote><div><br>This has been a great discussion. I think what we can agree on is what we don&#39;t recommend, the JSF managed bean container. What we can both get behind is a common set of annotations to hook into stronger bean containers such platform managed beans + CDI or platform managed bean annotations with Spring. @javax.annotation.ManagedBean + @javax.injectInject and do what you can to find a common ground for scopes ;)<br>
<br>I&#39;m glad that we can communicate with friendly exchanges and I always
look forward to getting your perspective. Frankly, I think that&#39;s what
defines this EG, as Andy so elegantly pointed out in his blog.<br><br>-Dan</div></div><br>-- <br>Dan Allen<br>Senior Software Engineer, Red Hat | Author of Seam in Action<br>Registered Linux User #231597<br><br><a href="http://mojavelinux.com" target="_blank">http://mojavelinux.com</a><br>

<a href="http://mojavelinux.com/seaminaction" target="_blank">http://mojavelinux.com/seaminaction</a><br><a href="http://www.google.com/profiles/dan.j.allen" target="_blank">http://www.google.com/profiles/dan.j.allen</a><br>