Wednesday, July 14, 2010

JSF Introduction

JavaServer Faces (JSF) technology, a server-side user-interface component framework for Java-based Web applications. This for those developers who are new to JSF and want to come up to speed quickly — not just with JSF, but with using JSF components to reduce efforts.

If you are doing Java server-side Web development, JSF is the easiest framework to learn. It is geared for creating Web applications. It allows you to focus on your Java code and without handling request objects, session objects, request parameters, or dealing with complicated XML files. With JSF, you can get more things done more quickly than with other Java Web frameworks.


1.1 JSF Features:

1) It's based on the Model-View-Controller (MVC Model-2) concept,
2) Built on top of Servlet API,
3) User Interface(UI) components(Stateful object) are stored on the server,
4) Backing beans - specialized JavaBeans with Getters & Setters method and Event Listener methods,
5) Navigation for navigating from one page to next,
6) Expession Language (JSF EL) used for wiring components to objects that expose JavaBean properties,
7) Validators for validating form,
8) Converters for converting value to and from a String for display,
9) Event driven programming model (Similar to Swing),
10) Events generated by user are handled on the server.
11) Messages for displaying Information or Error messages to the user,
12) Renderers responsible for displaying UI components, etc etc...



1.2 A JSF application

1) A JSF application consists of web pages with JSF UI components (JSP page).
2) Managed Bean(Java class).
– Getters and Setters, Action methods, Action listeners, Value-Change listeners methods.
3) A JSF application requires also some configuration files ("faces-config.xml" and "web.xml").

1.2.1 The faces-config.xml defines:

1) Managed Bean - the data elements of the JSF application (managed beans and backing beans) Represents a Java class which will be created dynamically during runtime of the JSF application. It can be defined for which scope the bean is valid (Session, Request, Application or none).
2) The Navigation between web pages
3) Data Validators - Used to check the validity of UI input
4) Data Converters -Used to translate between UI and model

1.2.1.1 Managed beans are simple Java objects (POJO's) which are declared in "faces-config.xml" and can be used in an JSF application. For example you can define a Java object "User". Once you define the object in faces-config.xml you can use the attributes of User in your JSF UI components, e.g. by binding the value "loginName" of this object to an JSF input field.



1.3 JSF EL
In JSF you can access the values of a managed bean via value binding. For value binding the universal Expression Language (EL) is used (to access bean and / or methods). In JSF you do not need to specify the get() or set() method but just the variable name.
Method binding can be used to bind a JSF component, e.g. a button to an method of a Java class.


NOTE: JSP EL expressions are using the ${...} syntax. These EL expressions are immediately evaluated. JSF EL expressions are of the type #{...}. These are only evaluated when needed (and otherwise stored as strings).

No comments:

Post a Comment