views:

1176

answers:

3

Hello,

I haven't used Spring, but it sounds like it is fairly popular. I heard that it provides alternate ways of doing things, such as being able to consume RESTful web services. Does anyone know if provides similar features as those introduced by JSF 2, or would I be comparing apples to oranges?

Edit:

Thanks for the information. Comparing Spring MVC to JSF 2, would there be advantages of using Spring MVC instead of JSF 2 functionality?

Thanks.

+4  A: 

Apples to Oranges.

Spring is an application framework that integrates dependency injection, aspect oriented programing and several other things in one stack. It's rough apples to apples comparison would be J2EE.

JSF is a view layer technology, built on the Model View Controller paradigm. Its rough oranges to oranges comparison would be Spring MVC. Both can use different View technologies (ie. Facelets, JSP, Velocity, etc.) and both integrate extremely well into their respective stacks.

-- In response to the new question --

I've used JSF2 a fair amount (as much as anyone can given its young age) and I find it to be a very good framework. It fixes a lot of the shortcomings of JSF 1.2 and I felt that JSF 1.2 was a good match for me too.

I've not used Spring MVC much but I have looked at some code that another developer has done.

My (very) limited experience is that Spring MVC feels slightly more like an "action" framework while JSF feels more like a "component" framework. I, personnaly, think that the component-esque frameworks are a more natural extension of OOD, which appeals to me and the way I write software.

Drew
Great, thanks for the input.
Jon
+3  A: 

Spring MVC is a web framework inside the Spring framework. It does provide features as those in JSF 2.0:

  • ajax-support
  • validation
  • dependency-injection
  • etc.

Yet, you can use Spring (not Spring MVC) together with JSF 2.0, with spring providing the dependency-injection, aop, transaction management mechanisms, and JSF providing the web layer.

Bozho
+1  A: 

JSF is just the view layer of the MVC and wil need to be used with other technologies like Spring/Hibernate or EJB for a full MVC.

Spring (not the Spring MVC) is the controller layer of the MVC and as I say can be used with something like JSF (Struts, JSP/Servlets etc) and something like Hibernate.

I have been using the Spring MVC for about 6 months now, whilst it's probably not the latyest version of SpringMVC I've found it a little annoying that we have so much XML to deal with. All the managed beans and DAO has XML config to it. Also everything seems to have to go thorugh a method called onSubmit().

JSF with something like EJB is far simplier in my opinion... Everything can be done using Annotations so simply use @ManagedBean=theBean in your backing bean and in your JSF put {thebean.param} and you have access to the backing bean's data. Also you can use the Session beans of your EJB as the backing beans for JSF then have direct acces to the DAO (Model layer) Entity bean. Again simply by using the @Entity annotation and the EntityManager class

Also I like the way you are free to set your own action methods so you can have a method in your bean called TheBean.addDetails() and call it in the JSF with theBean.addDetails() rather than everything going through one method as with the Spring MVC.

JSF as I say is just the view layer of MVC, personally I like using it with EJB as this gives you the full MVC all from within Suns J2EE.jar so there are no issues with making sure you have the correct versions and no configuration required.

JSF 2.0 is far suprior to JSF1.2 which always felt like half a job as with EJB3.1 which is nothing like EJB2.x and is far better than EJB3.0 even. For me JSF2.0 with EJB3.1 is so simple and easy to develop with and everything is very transparent.

Kappa
I disagree that JSF is "just a view layer". It can be used as standalone MVC application as good. It's however true that JSF is often used as the middle of "M(MVC)C". I myself by the way don't consider Spring as controller, but as injector. But I don't know Spring that good to post an explicit answer about that.
BalusC
Interesting, thanks for the info. Yeah I've been enjoying JSF 2 a lot, but am curious what else is out there. With JSF 2 you can have JSF be primarily the view layer, but model and controller code can sneak in also...
Jon