JavaServer Faces

JavaServer Faces ( JSF short ) is a framework standard for the development of graphical user interfaces for web applications. Based on servlets and JSP technology, JSF is one of the web technologies of the Java Platform, Enterprise Edition (Java EE). Using JSF developers can easily integrate components manner for user interface in Web pages and define the navigation. Conditions for the development of JSF content are the JDK, a servlet container (eg Apache Tomcat) and basic understanding of HTML, HTTP and the Java programming language. To simplify the development, an Integrated Development Environment be used.

  • 5.1 Scopes of Managed Beans ( eng. Scope)

Components

In order to reduce redundancies in the code and improve the reusability of UI code across multiple projects, components can be created and used. JSF components are subject to a hierarchical structure. Similarly, the Java Swing is in API Java Server Faces container components, the components may include. In order to structure the application better, is a distinction between high model, presentation and control as provided for by the model-view- controller concept.

A central concept of Java Server Faces is the view. It is a tree of JSF components. Such a structure occurs exactly once per call before, when using Java Server Pages ( JSP) so once per page. The view is set up at the beginning of the JSF life cycle, immediately after the arrival of the request from the client. In the last stage of the life cycle, the components of the views with the root starting to be called recursively to create the response, for example an HTML page. The controller component that controls user input can be implemented in Java Server Faces components have their own or with a so called handlers. These are usually written with Java. The actual logic of the application takes place in the model. For Java Server Faces the Model components are called Java Beans ( Java classes ) that are managed by the container. JSF Web applications usually have no appreciable HTML code. The HTML code is not visible in the source code of the generated page. JSF components have their own renderers. This renderer convert the written with JSF pages into HTML code so that each HTML web browser can display the page. Own renderer can be written for other output formats.

Life cycle

The specification of the Java Server Faces defines a so-called life cycle, to a JSF application with each call going through again. This life cycle is divided into six phases.

If errors occur, or to be called as a response, for example, an HTML page that does not contain JSF components, as individual phases can be skipped.

Implementations

The JavaServer Faces specification is implemented by a number of frameworks. These are usually included in JEE containers and can often replace only with difficulty. These include for example:

Component Frameworks

Component Frameworks extend JSF implementations. With them, for example, very simple JavaScript and Ajax are generated, thus increasing productivity when creating the code considerably.

  • ICEfaces, open source framework of ICEsoft; based on the Woodstock GUI component framework.
  • RichFaces Ajax4jsf including Red Hat (formerly Exadel )
  • Prime Faces
  • Mojarra Scales
  • J4Fry
  • Xulfaces
  • JQuery4jsf
  • MyFaces Trinidad by the Apache Software Foundation
  • MyFaces Tobago by the Apache Software Foundation
  • MyFaces Tomahawk by the Apache Software Foundation
  • Oracle ADF component library, a commercial Java framework for Java enterprise applications ( has some core functionality with Apache MyFaces Trinidad shared)

Various companies also offer graphical development tools for JSF.

Standardization

The JSF specification was under the Java Community Process (JSR 127 ) from a number of well known companies developed and adopted on 27 May 2004 in the version 1.1. On 11 May 2006 the version 1.2 ( JSR 252) has been released. The current version of the reference implementation Mojarra 1.2_15 was released on 24 September 2010.

Version 2.0 (JSR 314) brought particular Ajax support with it. It is available since December 2009 and can be downloaded from the Oracle website. An implementation as well as a tutorial and other documentation are available in the Mojarra Project ready to view and download the current version of Mojarra reference implementation is 2.0.8. In JSF 2.1 is a maintenance release of version 2.0, the specification was released on November 21, 2010, the current version of Mojarra reference implementation is 2.1.6. The current version of JSF 2.2 was released on April 15, 2013 .. They include the following new features: support for HTML5, such as the passing through of the new HTML5 attributes or custom data attributes, Advanced Flow support from its own Contexts and Dependency Injection Scope ( @ Flow Scoped ) in addition to the already existing Conversation Scope ( @ Conversation Scoped ), Stateless Views by setting the attribute transient = "true", and resource Library Contracts, a first approach to resources for selectable appearance to provide.

JavaServer Faces includes

  • A tag library to integrate the JSF interface components in JavaServer Pages or in a facelet,
  • A Java API for the control of control elements of the user interface. This includes handling events, validating the input, navigation and support for internationalization with a.
  • A separate Expression Language ( EL), which has as a basis the JSP technology. In JavaServer Faces EL expressions are written in the following notation: # { 1 2 }, # { PI / 2}, # { handler.attribut }

The main difference from the JSP EL is not only the a '#', but also in the language itself, the Java Server Pages Expression Language is more dynamic than the JavaServer Faces Expression Language. The JavaServer Faces EL is stateful (static ), comparable to the Java Swing components. The Expression Language JSF has a bidirectional binding values ​​, that is, they may Properties ( properties of a bean ) read (eg initialization) and write ( for example, bind values ​​to Property). The following table shows the modes of expression of the Expression Language of JSF:

In the development of JavaServer Faces pages should be dispensed with the combination of JSP and JSF expressions, since this can cause problems.

Managed bean mechanism

The managed bean mechanism allows POJOs with a specific scope ( eng. Scope) and initial values ​​for so-called Managed Properties ( also in the special case in which the bean is of type java.util.List or java.util.Map is ) to be provided, . This can be configured as an additional option with annotations directly in the bean either in the XML configuration of the JSF application from JSF 2.0, or (at least Java version 1.5). Managed beans can be used with the help of EL expressions directly ( eg in Facelets ).

Scopes of Managed Beans ( eng. Scope)

The scope of a bean defines how long a bean exists and under what circumstances it is considered to exist. As mentioned previously managed beans can be injected with Managed Properties in other managed beans. It should be noted that the injected bean has a larger scope than the bean into which it is injected. The reason for this is that the injected bean is otherwise potentially short-lived as the bean into which it is injected.

The following table shows all scopes in the current JSF version ( 2.1 ) by the size of the validity region with the shortest-lived scope to colonel.

JSF standard tags (not complete)

Use

JavaServer Faces aims to provide an easy way to write powerful web applications, without the need to ( ... state stateless protocol, Request, Response, ) make too much about the complexity of a Web application. In the development, it is also a programmer of a desktop application facilitates to write web applications. Since large companies have been involved in the specification, JavaServer Faces is the de facto standard.

432194
de