views:

426

answers:

3

Hi,

Yesterday I have seen a presentation on Java Server Faces 2.0 which looked truly impressive, even though I am currently a happy ASP.NET MVC / jQuery developer. What I liked most about JSF is the huge amount of AJAX-Enabled UI components which do seem to make development much faster than with ASP.NET MVC, especially on AJAX-heavy sites. Integration testing looked very nice too.

Since the presentation only emphasized the advantages of JSF, I'd like to hear about the other side as well.

So my questions are:

  • What are the main disadvantages of Java Server Faces 2.0?
  • What might make a JSF developer consider using ASP.NET MVC instead of JSF?

Thanks,

Adrian

A: 

I'll try to simplify based on my experience:

  • Not MVC. There's no excuse for that in this day and age.

  • Mix of Javascript libraries causes all kinds of nightmares while debugging. (similar to first issue.)

  • Not standards-compliant. There is more than one occasion where JSF will use illegal characters in HTML ID tags for example.

  • Performance - especially client side. Because of the anti-MVC nature, it is very difficult to optimize. Pity the poor folks running Netbooks or any kind of mobile device, let alone those regular folks who like to have lots of tabs open.

ASP.NET MVC is MVC. You can choose to use their AJAX, or write your own. Choose their scaffolds / templates, or write your own. Microsoft is updating ASP.NET at a MUCH faster rate and doing so with the idea of being standards-compliant at some point, whereas JSF is old and now that Oracle owns it, its future may be in question.

Josh
Thanks for your reply, but it leaves me confused. From Wikpedia: "JSF is a request-driven MVC web framework based on component driven UI design model, using XML files called view templates or Facelets views". The presentation also emphasized that JSF is following the MVC pattern. Could you elaborate on why JSF is NOT MVC in your opinion?
Adrian Grigore
JSF's interpretation of MVC patterns is different from .NET's interpretation. JSF will output View-layer HTML and JavaScript that you cannot control or change without going into Controller code. .NET keeps such outputs in places where designers / View-layer developers can easily access and maintain.
Josh
@Josh: Sounds a lot like ASP.NET's problems to me. Thanks for your reply!
Adrian Grigore
@Josh: I wasn't aware of the differences between JSF 2 and the old release of JSF when I wrote the OP, otherwise I would have been more specific. Which version of JSF did you work with?
Adrian Grigore
+18  A: 

JSF 2.0 disadvantages? Honestly, no serious disadvantages comes to mind. JSF in its current release still need to get rid of the negative imago as it was grown during the early ages. In the history there were indeed several serious disadvantages.

JSF 1.0 (March 2004)

This was the initial release. It was cluttered of bugs in both the core and performance areas you don't want to know about. Your webapplication didn't always work as you'd intuitively expect. You as developer would run hard away crying.

JSF 1.1 (May 2004)

This was the bugfix release. The performance was still not much improved. There was also one major disadvantage: you can't inline HTML in the JSF page flawlessly. All plain vanilla HTML get rendered before the JSF component tree. You need to wrap all plain vanilla in <f:verbatim> tags so that they get included in the JSF component tree. Although this was as per the specification, this has received a lot of critism.

JSF 1.2 (May 2006)

This was the first release of the new JSF development team lead by Ryan Lubke. The new team did a lot of great work. There were also changes in the spec. The major change was the improvement of the view handling. This not only fully detached JSF from JSP as view technology, but also allowed developers to inline plain vanilla HTML in the JSF page without hassling with <f:verbatim> tags. Another major focus of the new team was improving the performance. During the lifetime of the Sun JSF Reference Implementation 1.2 (which was codenamed Mojarra since build 1.2_08, around 2008), practically every build got shipped with (major) performance improvements next to the usual (minor) bugfixes.

The only serious disadvantage of JSF 1.x (including 1.2) is the lack of a scope in between the request and session scope, the so-called conversation scope. This forced developers to hassle with hidden input elements, unnecessary DB queries and/or abusing the session scope whenever one want to retain the initial model data in the subsequent request in order to successfully process validations, conversions, model changes and action invocations in the more complex webapplications. The pain could be softened by adopting a 3rd party library which retains the necessary data in the subsequent request like MyFaces Tomahawk <t:saveState> component, JBoss Seam conversation scope and MyFaces Orchestra conversation framework.

Another disadvantage is that JSF uses the colon : as ID separator character to ensure uniqueness of the HTML element id in the generated HTML output, especially when a component is reused more than once in the view (templating, iterating components, etc). Because this is an illegal character in CSS identifiers, the CSS developers would need to use the \ to escape the colon in CSS selectors, resulting in ugly and odd-looking selectors like #formId\:fieldId {}.

Also, JSF 1.x didn't ship with ajaxical facilities out of the box. Not really a technical disadvantage, but due to the Web 2.0 hype, it became a functional disadvantage. Exadel was early to introduce Ajax4jsf, which was thoroughly developed during the years and became the core part of JBoss RichFaces component library. Another component libraries were shipped with builtin ajaxical powers as well, the well known one being IceFaces.

About halfway the JSF 1.2 lifetime, a new XML based view technology was introduced: Facelets. This offered enormously a lot of advantages above JSP, especially in the area of templating.

JSF 2.0 (June 2009)

This was the second major release. There were a lot of technical and functional changes. JSP is replaced by Facelets as the default view technology and Facelets was expanded with capabilities to create custom components using pure XML (the so-called composite components). Ajaxical powers were introduced in flavor of the <f:ajax> component and like which has much similarities with Ajax4jsf. Annotations and convention-over-configuration enhancements were introduced to kill the verbose faces-config.xml file as much as possible. Also, the ID separator character : became configureable. All you need to do is to define it as init-param in web.xml with the name javax.faces.SEPARATOR_CHAR and ensuring that you aren't using the character yourself anywhere in client ID's, e.g. _ or -.

Last but not least, a new scope was introduced, the view scope. It eliminated another major JSF 1.x disadvantage as described before. You just declare the bean @ViewScoped to enable the conversation scope without hassling all ways to retain the data in subsequent (conversational) requests. A @ViewScoped bean will live as long as you're subsequently submitting and navigating to the same view (independently of the opened browser tab/window!), either synchronously or asynchronously (ajaxical).

Although practically all disadvantages of JSF 1.x were eliminated, there are JSF 2.0 specific bugs which might become a showstopper. As far as I see, only two one springs out: The view scope fails when you bind a component to the backing bean or when you use JSTL c:forEach or c:if in the view. Also, due to a bug in the PostAddToViewEvent under each IceFaces has frozen the release of its new JSF 2.0 component library for a long time (this is fixed in Mojarra release 2.0.3). Those bugs are however workaroundable.

With JSF 2.0, more nice-looking component libraries were born, under each PrimeFaces and OpenFaces.

See also:

BalusC
Thanks a lot for your comprehensive reply! :-)
Adrian Grigore
Wish I could give a +2.
Dean J
**Very** nice answer, the kind of answer I like to find on SO (+1)
Pascal Thivent
+1 great answer
Damo
+1  A: 

"JSF will output View-layer HTML and JavaScript that you cannot control or change without going into Controller code."

Actually JSF gives you the flexibility, you can either use standard/third-party components or create your own which you have full control over what is rendered. It is just one xhtml you need to create your custom components with JSF 2.0.

Cagatay Civici