|
A short treatise on
|
JavaServer (JSF) is a user-interface (UI) component based the Java web application framework. JSF is serverbased, that is the JSF UI components and their state are represented on the server. A JSF application run in a standard web container, e.g.: Tomcat, GlassFish, Jetty, etc. JSF defines a standard life-cycle for the UI components.
JSF is part of the Java EE standard, formerly known as J2EE. Sun Microsystems provides a reference implementation but there are also alternatives such as Apache MyFaces.
A JSF application consists of web pages containing JSF UI components. This application requires two configuration files, web.xml and faces-config.xml".
web.xml is identical in use and composition to this file in a JavaServer Pages (JSP) application. JSF builds on JSF as a logical step beyond.
faces-config.xml defines:
A managed bean is a type of JavaBean or reusable software component, that is created and initialized with dependency injection. Dependency injection is a technique for supplying external values upon which a component or bean is dependent, usually for its initialization.
Beginning in Java EE 6, a managed bean is a Java class that...
Consider the class Person, ...
package com.etretatlogiciels.jsf.treatise; public class Person { String firstName; . . . }
Managed beans are "plain, old Java objects" (POJOs) declared in faces-config.xml. For example, you can define a Java object Person. Once you define the object in faces-config.xml you use the attributes of Person in your UI components by binding the field, say, firstName of an object of this class to a JSF input field.
JSF uses the Java Unified Expression Language, used also by JSP, to bind UI components to object attributes or methods. This "language" consists of the XML tags you will come to recognized in the JSP/JSF code.
A managed bean is specified in faces-config.xml thus:
<managed-bean> <managed-bean-name> Person </managed-bean-name> <managed-bean-class> com.etretatlogiciels.jsf.treatise.Person </managed-bean-class> <managed-bean-scope> session </managed-bean-scope> </managed-bean><managed-bean-scope> session|request|application|none </managed-bean-scope>
It is the framework within the Tomcat (etc.) container that ensures the communication of values between HTML (user/presentation) and the component (POJO).
There are three different types of dependency injection.
The benefits of dependency injection are...
Drawbacks...
In Eclipse, edit faces-config.xml and use the Managed Bean tab of the editor to create of your Java class a managed bean. Use the Initialization section to initialize the bean's properties even if they are a Map or List. In addition to the "managed-bean" specification (illustrated previously), a paragraph for "managed-property" can be added that looks like this:
<managed-property> <property-name> firstName <property-name> <property-class> com.etretatlogiciels.jsf.treatise.Person <property-class> <value> #{firstName} </value> </managed-property>
In JSF you access the values of a managed bean via value binding rather than writing code to call getters and setters.
JSP begins the concept of separating the efforts of an application between the model, the view and the controller. JSP already separates state between UI components; each component is aware of its data.
JSF introduces a separation of the functionality of a component from its presentation (or display). HTML rendering is responsible for for separate client presentation.
There are versions of JSF. JSF 1.2 is built directly atop JSP and uses JSTL tags. JSF 2.0 uses Facelets.
(Left off at 4.0.)