I am trying to figure out what is the advantage of using JSF with spring MVC apart from set of different UI component that JSF implementation provides? Both are MVC and both have different perspective navigational handling (in way both are simple to understand). Suppose I go with JSF and Spring MVC together in my application, what are the benefit that would get for design, implementation and maintenance?
3 Answers
They are both MVC, but JSF is component oriented, while Spring MVC is action-based.
You can best look up what those terms exactly mean yourself, but in short JSF allows a UI to be composited of high level visual building blocks (sliders, panels, progress bars, etc).
Spring MVC doesn't say that much about the actual UI. It emphasis a controller, which you map to a URL path and its parameters. After processing you direct/forward to something that renders a view (typically a JSP, but lately Thymeleaf is often used).
JSF is a part of Java EE, which also comes with a framework that has somewhat of the "class-to-URL" binding aspects of Spring MVC; JAX-RS. JAX-RS itself is neither an MVC nor request-based web framework though, but a web-services framework.
Using two different web frameworks in one app is very confusing and I can't recommend this.
Wait man !!!
MVC is an architectural pattern that creates a conceptual division (in the application architecture) between:
- Model: that provides methods to access the data used by the application
- View: which deals with the display of the data contained in the model, and manages the interaction with users and agents
- Controller: receives commands from the user (usually through the view) and implements changing the status of the other two components
This scheme, among other things, also implies the traditional separation between the application logic (in this context often called "business logic"), out of the controller and model, and the user interface to load the view
So the MVC is an architectural pattern and has not to do with a specific language or a specific technology. Spring MVC is a Java framework that implements this pattern !!!
Ok, for the view we can use different technologies including JSF (Java Server Faces) that provide you some pre-made components (implemented by a specific View framework) that you have to declare using a tag library directly inside your views.
Nowadays there are many free View frameworks derived from JSF such as PrimeFaces and IceFaces.
JSP and all the framework derived by it natively support AJAX hiding from the programmer, so the developer does not have to worry about it
I suggest you to have a look at the PrimeFaces Component Showcase that explains to you all the power of this view technology:
http://www.primefaces.org/showcase/ui/home.jsf
For example you can handle AJAX FORM without knowing it in depth and especially without knowing or using Javascript.
This is the simplest AJAX form example that you can find in the showcase: http://www.primefaces.org/showcase/ui/pprUpdate.jsf
Using this kind of view technology you can use many components for form, menu and many other stuff
The main advantage is not having to write a single line of JavaScript using in place of components
-
Well I got the point that JSF implementation provider made life easy with many rich component. but What is the advantage using JSF with Spring MVC? Advantage I mean, lets say I am writing 100 lines code if I choose just JSF, but JSF with Spring MVC, my coding is reduced to 80 lines. Also another scenario is If i am developing application which requires frequent changes, how does choosing JSF and Spring MVC would help? Does it make maintenance less painful?– ChetanDec 8, 2012 at 20:56
-
The main advantage is the fact that you can implement RIA views (Rich Internet Interfaces: en.wikipedia.org/wiki/Rich_Internet_application ) without know Javascript (or some Javascript framework as JQuery) using in place of pre-made components that are very good for the for most common uses. In practice you can not know Javascript and not having to reinvent the wheel every time you need to implement a common use case (handling forms, menus, etcetc) Dec 9, 2012 at 8:32
-
Not agree with that view point about using JSF and Spring MVC all together. JSF isn't pure view at all, Facelets-JSP's are. It's oriented to the view, but it keeps being a full MVC framework. JSF and Spring MVC are, IMHO, at the same level, as Struts can also be.– AritzFeb 28, 2014 at 10:09
I will not repeat the definition from the other answers. JSF (and its components suites) help you to build applications faster because it's your job only to glue everything up once and just focus on business rules (or add value to your app) and build a UI by combining components.You don't have to test your components or concert mostly for Javascript.
In Spring MVC you start slowly, but it comes with a lot of freedom to implement whatever you want instead of depending on components (which mostly are just Javascript UI that communicates with JSF) or even implement Web Services without much hassle. But you will have to test, test and test such UI constructs.
If you are looking for a hybrid, maybe Spring Web Flow would be helpful. With it, you can use the JSF components and a nice abstraction layer for the Spring MVC controllers and even you can still use them if you want to.