Jakarta Faces#JSF and AJAX

{{Short description|Jakarta EE specification}}

{{tone|date=November 2012}}

{{Infobox software

| name = Jakarta Faces

| title = Jakarta Faces

| logo =

| screenshot =

| caption =

| collapsible =

| author = Sun Microsystems

| developer = Eclipse Foundation

| released =

| discontinued =

| latest release version = {{wikidata|property|reference|edit|Q729427|P348}}

| latest release date = {{wikidata|qualifier|raw|Q729427|P348|P577}}; {{Time ago|{{wikidata|qualifier|raw|Q729427|P348|P577}}}}

| latest preview version =

| latest preview date =

| programming language = Java

| operating system =

| platform =

| size =

| language =

| genre = Web application framework

| license =

| website = {{Official URL}}

}}

Jakarta Faces, formerly Jakarta Server Faces and JavaServer Faces (JSF) is a Java specification for building component-based user interfaces for web applications.[https://jakarta.ee/specifications/faces/4.0/ Jakarta Faces 4.0] It was formalized as a standard through the Java Community Process as part of the Java Platform, Enterprise Edition. It is an MVC web framework that simplifies the construction of user interfaces (UI) for server-based applications by using reusable UI components in a page.{{cite web | title = JSF 2.0 Tutorial | url = http://www.mkyong.com/tutorials/jsf-2-0-tutorials/ | publisher = mkyong | publication-date = 2010-12-12 | access-date = 2017-04-28 | quote = JavaServer Faces (JSF) 2.0, is an MVC web framework which focus on simplifies building user interfaces (comes with 100+ ready UI tags) for Java web application and make reusable UI component easy to implement.}}

JSF 2.x uses Facelets as its default templating system. Users of the software may also use XUL or Java.[https://rogerkeays.com/novdl-write-your-jsf-views-in-pure-java NoVDL: Write your JSF views in pure Java] JSF 1.x uses JavaServer Pages (JSP) as its default templating system.

History

{{expand section |date=August 2013}}

In 2001, the original Java Specification Request (JSR) for the technology that ultimately became JavaServer Faces proposed developing a package with the name javax.servlet.ui{{cite web |url=https://www.jcp.org/en/jsr/detail?id=127 |title=JSR 127: JavaServer Faces |year=2014 |website=Java Community process |publisher=Oracle Corporation |access-date=2014-08-05 |quote=2.6 Is there a proposed package name for the API Specification? (i.e., javapi.something, org.something, etc.) [:] javax.servlet.ui

}}

In June 2001, JavaWorld would report on Amy Fowler's team's design of "the JavaServer Faces API" (also known as "Moonwalk") as "an application framework for creating Web-based user interfaces".{{cite news |last1=Armstrong |first1=Eric |date=2001-06-06 |df=mdy |url=https://www.infoworld.com/article/2075969/java-web-services--what-s-not-to-like-.html |title=Java Web services: What's not to like? |work=JavaWorld |access-date=2020-07-27 |quote=The JavaServer Faces API (aka Moonwalk) promises to provide an elegant solution for implementing interactive functionality on incompatible browsers. [...] Designed by a team led by Amy Fowler, Sun's AWT and Swing architect, the JavaServer Faces API will provide a collection of GUI tools that will run on common browsers using standard HTML.

}}

=Developments=

Facelets (which was designed specifically for Java Server Faces) was adopted as the official view technology for JSF 2.0. This eliminates the life-cycle conflicts that existed with JSP, forcing workarounds by Java developers.{{cite web|last=Bergsten|first=Hans|url=http://onjava.com/pub/a/onjava/2004/06/09/jsf.html|title=Improving JSF by dumping JSP|publisher=O'Reilly|access-date=18 August 2011}}

The new JSF developments also provide wide accessibility to Java annotations such as @ManagedBean, @ManagedProperty and @FacesComponent that removes the need for faces-config.xml, in all cases except framework extension. Navigation is also simplified, removing the need for faces-config.xml navigation cases. Page transitions can be invoked simply by passing the name of the desired View or Facelet.

The addition of Partial State Saving and Document Object Model (DOM) updates are part of the built-in standardized AJAX support.

The latest JSF release has built-in support for handling resources like images, CSS and Javascript, allowing artifacts to be included with component libraries, separated into JAR files, or simply co-located into a consistent place within the Web application. This includes logical naming and versioning of resources.

JSF 2.0 also includes a number of other changes like adding support for events, separate development, staging, and production modes, similar to RAILS_ENV in Ruby on Rails, and significantly expanding the standard set of components.

=Update history=

  • JSF 4.0 (2022-05-15) {{En dash}} Major features: Deleted some deprecated things (native managed beans, native EL references), no extended view by default, added ClientWindowScoped
  • JSF 3.0.0 (2020-10-28) {{En dash}} Package name changed from Javax to Jakarta.
  • JSF 2.3 (2019-09-10) {{En dash}} The first release of the Jakarta Server Pages API for Jakarta EE.Neither the API nor the behavior has changed.
  • JSF 2.3 (2017-03-28) – Major features: search Expressions, extensionless URLs, bean validation for complete classes, push communication using WebSocket, enhanced integration with CDI.{{cite web |last1=Tijms |first1=Arjan |url=https://arjan-tijms.omnifaces.org/p/jsf-23.html |title=What's new in JSF 2.3? |work=Musings of a Java EE developer |access-date=2020-07-27}}
  • JSF 2.2 (2013-05-21) – Introduced new concepts like stateless views, page flow and the ability to create portable resource contracts.[https://blog.oio.de/2013/04/16/jsf-2-2-jsr-344-is-final/ JSF 2.2 (JSR-344) is final |techscouting through the java news] {{Webarchive|url=https://web.archive.org/web/20200727214224/https://blog.oio.de/2013/04/16/jsf-2-2-jsr-344-is-final/ |date=2020-07-27 }}. Blog.oio.de. Retrieved on 2020-07-27.
  • JSF 2.1 (2010-11-22) – Maintenance release 2 of JSF 2.0. Only a very minor number of specification changes.[https://blog.oio.de/2010/11/24/jsr-000314-javaservertm-faces-2-1/ JSR 314 JavaServer Faces 2.1 JSF 2.1 |techscouting through the java news] {{Webarchive|url=https://web.archive.org/web/20200727214253/https://blog.oio.de/2010/11/24/jsr-000314-javaservertm-faces-2-1/ |date=2020-07-27 }}. Blog.oio.de. Retrieved on 2020-07-27.{{cite web |url=http://it-republik.de/jaxenter/news/Was-ist-neu-in-JSF-2.1-057653.html |title=Was ist neu in JSF 2.1 |last=Bosch |first=Andy |date=2010-11-29 |publisher=it-republik.de |access-date=2013-02-19 |language=de}}
  • JSF 2.0 (2009-07-01) – Major release for ease of use, enhanced functionality, and performance. Coincides with Java EE 6.
  • JSF 1.2 (2006-05-11) – Many improvements to core systems and APIs. Coincides with Java EE 5. Initial adoption into Java EE.
  • JSF 1.1 (2004-05-27) – Bug-fix release. No specification changes.
  • JSF 1.0 (2004-03-11) – Initial specification released.

How it works

Based on a component-driven UI design-model, JavaServer Faces uses XML files called view templates or Facelets views. The FacesServlet processes requests, loads the appropriate view template, builds a component tree, processes events, and renders the response (typically in the HTML language) to the client. The state of UI components and other objects of scope interest is saved at the end of each request in a process called stateSaving (note: transient true), and restored upon next creation of that view. Either the client or the server side can save objects and states.

=JSF and AJAX=

{{anchor|Mojarra}}

{{Infobox software

| name = Mojarra

| logo =

| logo caption =

| logo alt =

| logo size =

| collapsible =

| screenshot =

| screenshot size =

| screenshot alt =

| caption =

| other_names = JSF RI

| author = Sun Microsystems

| developer = Eclipse Foundation

| released = {{Start date and age|2004|03|03}}

| ver layout =

| discontinued =

| latest release version = {{wikidata|property|edit|reference|Q111171534|P348}}

| latest release date = {{start date and age|{{wikidata|qualifier|Q111171534|P348|P577}}}}

| latest preview version =

| latest preview date =

| repo = {{URL|{{wikidata|property|Q111171534|P1324}}}}{{EAW|qid=Q111171534|pid=P1324}}

| qid =

| programming language = Java

| middleware =

| engine =

| operating system =

| platform = Jakarta EE

| included with =

| replaces =

| replaced_by =

| service_name =

| size =

| standard =

| language =

| language count =

| language footnote =

| genre = web framework

| license = EPL-2.0

| website = {{URL|{{wikidata|property|Q111171534|P856}}}}{{EAW|qid=Q111171534|pid=P856}}

| AsOf =

}}

JSF is often used together with AJAX, a Rich Internet application development technique. AJAX is a combination of web development techniques and technologies that make it possible to create rich user interfaces. The user interface components in Mojarra (the JSF reference implementation{{cite web

|last=Lubke |first=Ryan

|date=2007-12-05 |df=dmy

|title=Project Mojarra - the JSF RI gets a code name

|work=Ryan Lubke's Blog

|publisher=Sun Microsystems

|agency=Oracle Corporation

|url=https://blogs.oracle.com/rlubke/entry/project_mojarra_the_jsf_ri

|archive-url=https://web.archive.org/web/20170407234739/https://blogs.oracle.com/rlubke/entry/project_mojarra_the_jsf_ri

|archive-date=2017-04-07

}}) and Apache MyFaces were originally developed for HTML only, and AJAX had to be added via JavaScript. This has changed, however:

Because JSF supports multiple output formats, AJAX-enabled components can easily be added to improve user interfaces created with JSF. The JSF 2.0 specification provides built-in support for AJAX by standardizing the AJAX request lifecycle and providing simple development interfaces to AJAX events. The specification allows an event triggered by the client to go through validation, conversion, and method invocation, before returning the result to the browser via an XML DOM update.

JSF 2 includes support for graceful degradation when JavaScript is disabled in the browser.

AJAX-enabled components and frameworks

The following companies and projects offer AJAX-based JSF frameworks or component libraries:

Criticisms

= ThoughtWorks, 2014 =

In their January 2014 Technology Radar publication, ThoughtWorks wrote:{{cite web |url=http://thoughtworks.fileburst.com/assets/technology-radar-jan-2014-en.pdf |title=Technology Radar |publisher=ThoughtWorks |date=January 2014 |page=12 |access-date=2014-01-30 |archive-url=https://web.archive.org/web/20160407102412/http://thoughtworks.fileburst.com/assets/technology-radar-jan-2014-en.pdf |archive-date=2016-04-07 |url-status=dead }}

{{blockquote|text=We continue to see teams run into trouble using JSF – JavaServer Faces – and are recommending you avoid this technology. Teams seem to choose JSF because it is a JEE standard without really evaluating whether the programming model suits them. We think JSF is flawed because it tries to abstract away HTML, CSS and HTTP, exactly the reverse of what modern web frameworks do. JSF, like ASP.NET webforms, attempts to create statefulness on top of the stateless protocol HTTP and ends up causing a whole host of problems involving shared server-side state. We are aware of the improvements in JSF 2.0, but think the model is fundamentally broken. We recommend teams use simple frameworks and embrace and understand web technologies including HTTP, HTML and CSS.}}

== Rebuttal ==

In February 2014, Çağatay Çivici (PrimeFaces Lead) responded to ThoughtWorks criticisms in a post titled JSF is not what you've been told anymore. Çivici argues that improvements in JSF over the years offer many features that embrace modern web development, providing the option to write your own JavaScript, HTML, and CSS. Also regarding state, Çivici wrote:{{Cite web|date=2014-02-12|title=JSF is not what you've been told anymore|url=https://www.primefaces.org/jsf-is-not-what-youve-been-told-anymore/|archive-url=https://web.archive.org/web/20170910221440/https://www.primefaces.org/jsf-is-not-what-youve-been-told-anymore/|url-status=dead|archive-date=September 10, 2017|access-date=2020-11-24|website=PrimeFaces|language=en-US}}

{{blockquote|text=JSF is a stateful framework by nature and state makes web applications easy to develop with. With improved state management techniques introduced in JSF 2.0+ (e.g. stateless mode, partial state saving), JSF can scale as well.}}

= DZone, 2014 =

In the article published November 2014 in the DZone website, titled "Why You Should Avoid JSF", Jens Schauder wrote:{{cite web |author=Jens Schauder|url=https://dzone.com/articles/why-you-should-avoid-jsf|title=Why You Should Avoid JSF | publisher=DZone |date=November 2014}} {{blockquote|text=Facelets, the preferred presentation technology of JSF looks at first sight like an ordinary templating technology like the good old JSP or Thymeleaf. But if you look closer the horror becomes obvious. In the same place where you structure your HTML, you also place the logic what parts of the UI should get updated on an action. A clear violation of the separation of concerns principle in my book. Even better is the immediate attribute which changes the server side life cycle! And if this isn't enough it does it in different ways depending on what tag you use it on. You can't make stuff like this up.}}

= TheServerSide, 2016 =

In February 2016, the enterprise Java community website TheServerSide published an article recommending against the use of JSF, whose use could compromise the quality of the final product. The article ellaborated on five reasons:{{cite web |url=https://www.theserverside.com/feature/Five-drawbacks-to-choosing-JSF-as-your-web-application-framework |title=Five drawbacks to choosing JSF as your web application framework |last=McKenzie |first=Cameron |website=TheServerSide |date=February 16, 2016 |access-date=December 22, 2020}}

  1. Simple tasks become difficult;
  2. JSF lacks flexibility;
  3. The learning curve is steep;
  4. Incompatibility with standard Java technologies; and
  5. Primitive AJAX support.

References

{{Reflist}}