Sunday, January 5, 2014

I was reading about JSF that its a UI framework and provides some UI components. But how is it better or different from number of components that can are available from extjs or jQuery or combination of css and html and js. Why should someone learn JSF.
share|improve this question
 
advantages of server-generated html: search engine searchability, hide views based on authorization. otherwise, we have abandoned it for pure ajax ui. –  Neil McGuigan Oct 1 '12 at 17:45
 
I have also abandoned JSF in favor of AngularJS + RESTful backend. (Apples and oranges, but Angular is so nice I don't need many of the benefits of JSF) –  arg20 Nov 16 '13 at 3:53
add comment

6 Answers

up vote55down voteaccepted
JSF to plain JSP/Servlet/HTML/CSS/JS is like as jQuery to plain JS: do more with less code. To takePrimeFaces as an example, browse through its showcase to see complete code examples. RichFaceshas also a showcase with complete code examples. If you study those examples closely, then you'll see that you basically need a simple Javabean class as model and a XHTML file as view.
Note that you should not see JSF as replacement of alone HTML/CSS/JS, you should also take the server side part into account (specifically: JSP/Servlet). JSF removes the need of all the boilerplate of gathering HTTP request parameters, converting/validating them, updating the model values, executing the right Java method to do the business stuff and generating the HTML/CSS/JS boilerplate code. With JSF you basically end up with a XHTML page as view definition and a Javabean class as model definition. This greatly speeds up development.
As with every component based web MVC framework, you have in JSF less fine-grained control over the rendered HTML/CSS/JS. Adding custom JS code isn't that easy as you have to take the JSF view state in the server side into account as well (e.g. enabling a disabled button in JS side won't enable the button in JSF side, which is in turn a huge security advantage). If that is however a major showstopper, then rather look for an action based web MVC framework like Spring MVC. You'll only take into account that you have to write all that HTML/CSS/JS code yourself. Also if you fall back from Facelets to JSP, you'll miss advanced templating capabilities as well.
On the other hand, if you have a big JSP/Servlet/HTML/CSS/JS/jQuery based website and you'd like to refactor the repeated JSP/Servlet/HTML/CSS/JS/jQuery boilerplate code into reusable components, then one of the solutions would be JSF. Custom templates, tagfiles and components can aid in this. In that perspective, JSF stands above JSP/Servlet/HTML/CSS/JS/jQuery (and that's also why it's pretty important to understand those basics before diving into JSF).

See also:

share|improve this answer
6 
Do more with less code? But with more xml... what a tradeoff... additionally, it robes you of flexibility – Łukasz L. Nov 25 '11 at 13:41
11 
In JSF 2.0+, xml is not necessary. –  Cagatay Civici Nov 26 '12 at 14:23
add comment
JSF was created to make it so that java shops didn't have to learn stuff like jQuery and buil complex js but instead focus on a purely Java stack. In a world where time is money and lots of places already focusing on Java development, one less language/piece in the stack makes training and maintaining faster and thus cheaper.
I'll add that JavaScript is easy to become a maintenance nightmare on large teams, especially if some of the developers on the project are not highly web savy.
share|improve this answer
 
So if am pretty comfortable with JQuery JS etc. I need not be concentrating on JSF? –  sushil bharwaniDec 12 '10 at 14:10
2 
It all depends on the problem you are trying to solved and what team you are solving it with. –  Andrew WhiteDec 12 '10 at 15:15
 
I agree on team, but i am interested in learning what different problems can JSF solve and js jQuery etc cannot. Just trying to buildup motivation to learn JSF. –  sushil bharwani Dec 12 '10 at 15:33
1 
None, it just provides a different way to solve the same problems. –  Andrew White Dec 12 '10 at 16:18
3 
Even if you're really comfortable with JQuery, JSF is still really useful. It provides an easy way to connect server side code to client side representations. Some Facelets 'composite components' are only a rather thin wrapper around HTML and JS (including JQuery). They're a breeze to build and in general just make the whole client-server side connection way easier. –  Arjan Tijms Dec 13 '10 at 23:15
add comment
With Javascript and frameworks such as jQuery you have full flexibility and full control . Wwith ext's etc you lose much control and must adapt to the framework. With JSF you totally lose control and must totally adapt to the framework. You're invoked in lifecycles etc. and finally you have no control when the call to the server can be made and where not. If you are to do something considered 'special', you're in very hard position. And in JSF world even such basic things as multicolumn table sort or fields where you can type only limited set of characters (such as number field) are considered 'special'.
However, the more flexibility you have, the more errors or bad practices you can made. High flexibility works only with highly intelligent programmers, others will turn the project into unmanagable nightmare.
But, with JSF and its limited flexibility, there's always only a few (or even only one) correct way to do something. You are very limited, you can't make shortcuts, you must write more XML etc. - but when adapting to standard, there's better control on the code the unexperienced or low-skilled programmers will produce. As a result, big corporations love JSF because it is 'safer' for them.
When I moved from GWT to JSF, I was shocked, how many things, that was natural to me, was considered highly untypical and how much simple things were so hard to achieve. What's more, even making the smallest changes, such as adding ':' sign after label, which in GWT/jQuery powered app would be changing one function generating label, required changing dozens of files with localized properties, which wasn't even considered by anyone except me strange...
share|improve this answer
1 
PrimeFaces is based on jQuery so you have lots of flexibility on client side, also PrimeFaces components provide many hooks on client and server side as event callbacks for you to customize. Javascript APIs can be overriden and CSS as well for customized look. : label can be configured globally in web.xml for a more jQuery friendly character. –  Cagatay Civici Nov 26 '12 at 14:26
add comment
I strongly disagree that jsf adds anything. It only adds overhead. Doing ui stuff on the server is the most ridiculous thing ive ever heard. And javascript on large teams works great - its called reusing code.
Just wrap the jquery in some jsp tags, thats all you need and youre done, and dont endure the.shackles and scalability issues with.jsf and richfaces.
share|improve this answer
3 
JSF is geared towards form based applications. jQuery is nice (heck, lot of popular JSF component libraries like PrimeFaces, RichFaces and IceFaces even use it under the covers), but jQuery doesn't simplify processing form submits in the server side in any way. Using plain JSP/Servlet will only result in terrible boilerplate code. Again, JSF is not only HTML/CSS/JS, but also JSP/Servlet. –  BalusC Apr 30 '12 at 17:34
add comment
The benefits of using JSF are not only in generating xhtml + css + js. Sometimes JSF imposes a restriction on the markup you can generate, like any component based framework. But JSF is not just for that, its lifecyle helps greately. After validating the input it can update the model and sync your server side beans without any effort. you just say "whatever the user types here, check if it's a number, if yes then store it in the property YY in object XX" and JSF will do all that.
So yes, you can still use JQuery, JS, etc. But JSF provides many benefits when it comes to writing server side code and saves you from a lot of boiler plate.
share|improve this answer
add comment
Having worked with JSF, Spring MVC, Struts, Grails, JQuery, and ExtJS my opinion is that Grails + ExtJS is one powerful combination.
I would pick Grails over JSF any day. I like the completeness of ExtJS as the client side framework and library, but it comes with a steeper learning curve than JQuery.
share|improve this answer