What is the need of JSF, when UI can be achieved with JavaScript libraries such as jQuery and AngularJS
Asked Answered
N

8

117

I was reading about JSF that it's a UI framework and provides some UI components. But how is it better or different from number of components that are available from jQueryUI, AngularJS, React, Vue.js, Svelte, ExtJS, or even plain HTML, CSS and JavaScript.

Why should someone learn JSF?

Navada answered 12/12, 2010 at 13:19 Comment(3)
advantages of server-generated html: search engine searchability, hide views based on authorization. otherwise, we have abandoned it for pure ajax ui.Branen
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)Dunderhead
JSF is a component based MVC framework which is built on top of the Servlet API, and provides components via taglibs which can be used in JSP or any other Java based view technology such as Facelets.Implosive
C
158

JSF to plain JSP/Servlet/HTML/CSS/JS is like as jQuery to plain JS: do more with less code. To take PrimeFaces (jQuery + jQuery UI based) as an example, browse through its showcase to see complete code examples. BootsFaces (jQuery + Bootstrap UI based) has 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 (and prevention against XSS, CSRF and DOM-manipulation!) 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).

You can find a real world kickoff JSF based project here: Java EE Kickoff App. You'll see that it contains next to JSF as good HTML5, CSS3 and jQuery.

See also:

Cap answered 12/12, 2010 at 23:40 Comment(5)
Do more with less code? But with more xml... what a tradeoff... additionally, it robes you of flexibilityMegaron
In JSF 2.0+, xml is not necessary.Superbomb
We have Annotations in JSF 2.0Prissy
It seems that there's not a clear delineation between the business/controller layer and the view, with JSF, as much of the view is generated on the server. I understand that everything gets compiled on the server before being sent to the browser, but I prefer my Java object returning data that the view renders, rather than sending rendering logic/data.Leukoderma
agree JSF is server side thing with powerful control over HTML.Afloat
F
30

JSF was created to make it so that java shops didn't have to learn stuff like jQuery and build 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 savvy.

Franfranc answered 12/12, 2010 at 14:5 Comment(7)
So if am pretty comfortable with JQuery JS etc. I need not be concentrating on JSF?Navada
It all depends on the problem you are trying to solved and what team you are solving it with.Franfranc
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.Navada
None, it just provides a different way to solve the same problems.Franfranc
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.Contusion
things have massively improved in the Javascript world with Angular, React, Typescript, Webstorm, Node etc. It no longer has to be a hacky mess.. you can have elegantly designed front ends with all the benefits of OO like inheritance, encapsulation etc.Daumier
@OliverWatkins I still think of JSF as much more productive and safe. And I think that separation in front and backend is not so good for being more prone to bad designs. Although I feel that the JSF has fallen into disuse, it is the best technology I have ever used.Rikki
M
23

With Javascript and frameworks such as jQuery you have full flexibility and full control . With 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...

Megaron answered 25/11, 2011 at 14:4 Comment(2)
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.Superbomb
Agreed. The general rule is: Using no framework requires advanced javascript programming and will be hard to maintain but allows significantly greater power and complexity, while reliance on frameworks will be easier to build and maintain, but will limit the potential capacity of the app.Humpback
D
11

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.

Dunderhead answered 11/4, 2012 at 12:47 Comment(0)
D
7

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.

Dwain answered 29/4, 2012 at 15:36 Comment(2)
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.Cap
I think if you read more on JSF in general and on the life cycle of a JSF page specifically, you might change your mind. Then again, you might not.Misinform
M
6

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.

Morphosis answered 15/10, 2012 at 22:22 Comment(0)
C
4

Here are the biggest differences between jQuery & JSF:

  • no MVC architecture
  • no state control (store date in session or conversation, auto-clean up, etc.)
  • no (default) validation library
  • no templating library
  • no advanced navigation/routing
  • client side

jQuery was never intended to be used as a full stack webframework. It was more intended for replacing low-level JS code so that writing JS becomes easier and more powerfull in less lines of code.

And it should thus mostly be used to add behaviour on HTML elements.

Chavarria answered 4/7, 2017 at 13:55 Comment(0)
M
2

Having used ExtJS framework for a large web application, I know how easy it is to use. The ExtJS (Schena) is best suited for (Oracle 11g) database interactions in MVC architecture. The View was for the visual / user interactions. The controller specified the 'processing' and the triggers that needed to be used form the PLSQL packages (the API for the CRUD, SQL select queries etc.). The Model and the store files were used to 'map' the data items to the Viewer / inputs.

ExtJS is not suitable for non database intensive web interfaces - where Angular JS may be a better fit.

Meade answered 30/12, 2016 at 23:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.