4

I am starting a new pretty big webapp and I am using Spring MVC for complete MVC architecure and I really don't want to change that. On top of that I am looking for a view technology and finally closed with JSF as JSF/facelets is in official EE specification which means they will be the future. Plus prime faces looks promising in acheiving good UI. I know JSF is a MVC framework and I just want to liverage its view part to reduce the development time and at the same time acheiving good and flexible responsive UI

But I went through several posts on StackOverflow itself which prohibits the use of Spring MVC + JSF. E.g, this one

This question was answered in 2011 and now new Java EE specification also got released and many changes has happened. Is this point still stands that we should not use JSF+Spring MVC? If it is true, then what are the replacements. One option that looks good for me is Thymeleaf, but only thing that is troubling me is that will it be a good idea to neglect an official specification?

Community
  • 1
  • 1
Abhinav
  • 3,322
  • 9
  • 47
  • 63
  • 1
    btw your linked question was answered in sep 2013, sep 11 means 2013-09-11, not sep 2011! so the answers there are relevant even now and good :) – AmeetC Oct 05 '13 at 10:30
  • Please re-read BalusC's answer one more time. Note that Spring MVC + JSF won't mix because both are view technologies. Instead, you want to use Spring + JSF. *JSF/facelets is in official EE specification which means they will be the future* it is not the future, it is **the present** and works. – Luiggi Mendoza Oct 05 '13 at 14:40
  • [Related question](https://stackoverflow.com/q/18744910/459391). See also [this post on Baeldung](https://www.baeldung.com/spring-jsf), where it describes how to use JSF with Spring (but not Spring **MVC**). – Sadeq Dousti Jan 16 '19 at 17:07

1 Answers1

7

JSF can probably be integrated (I'm not very sure, see the links at the end of my answer) with Spring MVC but it does not look a very good fit to me. Primarily since JSF is component based, while Spring MVC is action-based. In Spring MVC, the controllers do the processing and can pass the results to anything that renders the view (jsp, html, thymeleaf, apache tiles etc.). Thymeleaf is a good option and I like its approach to templates.

Other alternatives I would suggest to look instead of JSF:

  1. JS frameworks:

    I personally prefer this for my projects and there are tons of options to choose like jQuery/jQuery UI, ExtJS etc. for creating you views. You can combine these and make their elements work with fluid frameworks like Bootstrap so that they behave nicely on all screens sizes (not sure how PrimesFaces/RichFaces components behave on all devices)

  2. Frameworks that compile to JS:

    Here you have two good frameworks to choose from - Vaadin and GWT. I've used only Vaadin and not GWT so will not comment much on it. Choose this if you don't want to directly fiddle with javascript.

It is not true that only if you use the official Java EE spec you can be in sync with the future. HTML5, JS frameworks etc. are as much the future as JSF is, if not more! Ofcourse JSF of late looks good too (I have not made any production code with it yet, nevertheless have explored it in hobby projects) but you are better off using it on its own with PrimesFaces/RichFaces and not combine it with Spring MVC.

On a middle ground, you can use Facelets instead of Thymeleaf for templating views in Spring MVC. On the other side, you can use JSF with Spring DI, but as I said earlier don't mix JSF and its component libraries with Spring MVC.

Update: Just in case if you absolutely want to try it, here are some links:

Community
  • 1
  • 1
AmeetC
  • 280
  • 1
  • 7
  • 1
    If you and OP read carefully BalusC's answer in the given link on OP's question, you will understand that JSF and Spring MVC **doesn't mix**, but instead you can use JSF and Spring. Note that Spring MVC **is not** Spring. – Luiggi Mendoza Oct 05 '13 at 14:37
  • @LuiggiMendoza If you read carefully my answer, I made a clear distinction between Spring and Spring MVC in the last para by mentioning "Facelets ... in Spring MVC" and "JSF with Spring DI" (I could have just said Spring). I guess I never mixed Spring and Spring MVC – AmeetC Oct 05 '13 at 18:00
  • Also, I never tried doing it myself because of the reason I 'bolded' in the second sentence and I did read BalusC's answer carefully but I also know three places where this seems to be possible (see links in my updated answer) and based on that I told the OP "...can be integrated...". – AmeetC Oct 05 '13 at 18:01
  • *JSF Prime Faces can be integrated with Spring MVC* that's the beginning of your answer, and that sentence is wrong. What you mix is JSF and Spring, not JSF and Spring MVC, and after your edit you haven't updated this. – Luiggi Mendoza Oct 05 '13 at 20:20
  • Okay I updated that statement to avoid any confusion. Since you are stating that it just cannot be done, what do you say about the links I've given, it seems few people have made it happen. – AmeetC Oct 06 '13 at 06:09
  • Looks like possible after lot of configurations. If you follow a JSF 2 + Spring tutorial you'll save the time and the effort of doing all this =\ – Luiggi Mendoza Oct 06 '13 at 13:19