Tuesday, August 12, 2008

JSF Tags

JSF application typically uses JSP pages to represent views. JSF provides useful special tags to enhance these views. Each tag gives rise to an associated component. JSF provides 43 tags in two standard JSF tag libraries:

  1. JSF Core Tags Library and

  2. JSF Html Tags Library

Even a very simple page uses tags from both libraries.

<%@ taglib uri=”http://java.sun.com/jsf/core “ prefix=”f” %>
<%@ taglib uri=”http://java.sun.com/jsf/html “ prefix=”h” %>

……………
……………



In the above code fragment we have imported two JSF tag libraries with the help of taglib directive. JSF Core Tag Library contains set of JSF core tags while JSF Html Tags Library contains set of html tags. Prefix is used to use tags defined in tag library. Here we are using conventional names f and h for Core & Html tags respectively. We have the choice to choose any name for the prefixes.

  • JSF Html Tags:

    These tags represent html components like text fields, buttons, form.
    Html tags can be divided into following categories:

    Inputs (inputText, inputTextarea)
    Outputs (outputText, outputLabel)
    Commands (commandButton)
    Selections (selectOneRadio, selectOneListbox, selectOneMenu for radio buttons, list boxes, menu etc)
    Layouts (panelGrid)
    Data table (dataTable)
    Errors and messages (message, messages)

    Some examples have been given below to understand how to use these tags and its attributes:

    <h:inputText id=”ID1” value=”value”/>
    creates a single line text input control where id attribute is used to uniquely identify the component rendered by this tag and value attribute sets the current value of the component.

    <h:outputText id="ID2" value="Welcome"/>
    creates a single line text output where id attribute uniquely identifies the rendered component and current value is set by value attribute .

    <h:commandButton
    id="submit"
    value="go"
    action="nextPage">
    </h:commandButton>

    creates a command button where value attribute sets the value that is displayed on the button when it is rendered and action attribute is used to invoke a method defined in backing bean when a user does an action on the component .According to the return of the invoked method it is determined which view is to be displayed next.


    In JSF Html Tag Library there are 25 core tags .

    All JSF Html Tags :

    • column creates column in a dataTable
    • commandButton creates button
    • commandLink creates link that acts like a pushbutton
    • dataTable creates a table control
    • form creates a form
    • graphicImage displays an image
    • inputHidden creates hidden field
    • inputSecret creates input control for password
    • inputText creates text input control (single line)
    • inputTextarea creates text input control (multiline)
    • message displays the most recent message for a component
    • messages displays all messages
    • outputFormat creates outputText, but formats compound messages
    • outputLabel creates label
    • outputLink creates anchor
    • outputText creates single line text output
    • panelGrid creates html table with specified number of columns
    • panelGroup used to group other components where the specification requires one child element
    • selectBooleanCheckbox creates checkbox
    • selectManyCheckbox creates set of checkboxes
    • selectManyListbox creates multiselect listbox
    • selectManyMenu creates multiselect menu
    • selectOneListbox creates single select listbox
    • selectOneMenu creates single select menu
    • selectOneRadio creates set of radio buttons
  • JSF Core Tags:

    These tags allows you to take advantages of features of JSF framework, like validation, conversion , event handling. Core library is stepchild of Html library. i.e. core library supports the html library. Core tag library also contains tags for views and sub-views , loading resource bundle, adding arbitrary text to a page. Some examples of JSF core tags are:

    f: view tag is used to create top level view
    f: subview tag is used to create subview of a view.
    f: validator tag is used to add a validator to a component.
    f: converter tag is used to add an arbitrary converter to a component.
    f: actionListener tag is used to add an action listener to a component.
    f:valueChangeListener tag is used to add a valuechange listener to a component

    Some examples have been given below to understand how to use these tags:

    <f:view locale="en">

    </f:view>
    f: view tag is used to create top level view and is a container for all JSF component tags on a page. Where locale attribute provides several options for presenting localized views of your application. Here "en" represents English and if we give velue "fr" to locale attribute then french view will be displayed. So this attribute is useful for internationalization purpose.


    head


    view


    <f:subview id="sub_id">

    </f:subview>

    Here f:subview tag is like container for the JSF components contained in an included JSP page (second.jsp).


    <f:validator validatorId="Txt_Validator" />

    The Validator tag registers a Validator on the component associated with the enclosing tag. In validatorId field, we give the value of one of the validator-id element of a validator in your Faces configuration file.

In JSF Core Tag Library there are 18 core tags .

All JSF Core Tags:

  • f :view Creates the top-level view
  • f:subview Creates a subview of a view
  • f:attribute Adds an attribute to a component
  • f:param Constructs a parameter component
  • f:converter Adds an arbitrary converter to a component
  • f:converterDateTime Adds a datetime converter to a component
  • f:converterNumber Adds a number converter to a component
  • f:actionListener Adds an action listener to a component
  • f:valueChangeListener Adds a valuechange listener to a component
  • f:validator dds a validator to a component
  • f:validateDoubleRange Validates a double range for a component’s value
  • f:validateLength Validates the length of a component’s value
  • f:validateLongRange Validates a long range for a component’s value
  • f:facet Adds a facet to a component
  • f:loadBundle Loads a resource bundle, stores properties as a Map
  • f:selectitems Specifies items for a select one or select many component
  • f:selectitem Specifies an item for a select one or select many component
  • f:verbatim Adds markup to a JSF page

source: roseindia.net

SF Components

Components in JSF are elements like text box, button, table etc.. that are used to create UI of JSF Applications. These are objects that manage interaction with a user. You can create :

  1. Simple components, like text box, button and

  2. Compound components, like table, data grid .

A component containing many components inside it is called a compound component. Components help developers to create UIs by assembling a number of components , associating them with object properties and event handlers. Would u like to repeat the same code again & again and waste time if u want to create many tables in hundreds of pages in your web application? Not at all. Once you create a component, it’s simple to drop that component onto any JSP.

JSF allows you to create and use components of two types:

  1. Standard UI Components:
    JSF contains its basic set of UI components like text fields, check boxes , list boxes, panel , label, radio button etc. These are called standard components. For example:

    UIForm represents a user input form that is a container of other components.
    UICommand represents UI components like buttons, hyperlinks and menu items.
    UIInput represents UI components like text input fields, numeric input fields.

  2. Custom UI Components:
    Generally UI designers need some different , stylish components like fancy calendar, tabbed panes . These types of components are not standard JSF components. JSF provides this additional facility to let you create and use your own set of reusable components .These components are called custom components.

    One of the greatest power of JSF is to support third party components .Third party components are custom components created by another vendor. Several components are available in the market ,some of them are commercial and some are open source . You can use these pre-built & enhanced components in UI of your web application .Suppose u need a stylish calendar , u have an option to take it from third party rather than creating it .This will help you to save your time & cost creating effective & robust UI and to concentrate on business logic part of web application.
    If u want to create custom components then its necessary to either implement UIComponent interface or extend UIComponentBase class that provides default behavior of components. These may be responsible for its own display or the renderer is used for its display. These components are stored in component tree on the server and they maintain state in between client requests. These components are manipulated on the sever in java code.
    So the final conclusion of using third party components is that a more attractive , robust and functional UI can be created with fewer time, cost and man power.

source: roseindia.net

Sunday, August 10, 2008

How JSF Fits For Web Applications?

JSF best suits in to the java web development environment because of reasons described below : JSF has many advantages over other existing frameworks that makes it a better choice for web application development. Some of the reasons are below:

Easy creation of UI:
It makes easier to create complex UI for an applicaton using jsf tags.Its APIs are layered directly on top of servlet APIs that enables us to use presentation technology other than JSP,creating your own custom components and rendering output for various client devices.

Capacity to handle complexities of UI management:
It handles cleanly the complexities of UI management like input validation, component-state management, page navigation, and event handling.

Clean separation between presentation and logic:
One of the greatest advantage of jsf is to clearly separate behaviour and presentation in an application. JSF is based on the Model View Controller (MVC) architecture.

Shorter development cycle:
This separation between logic and presentation enables a wide range of users( from web-page designers to component developers). It allows members of team to focus on their own work only , resulting in division of labour and shorter development cycle.

Standard Java framework:
JSF is a Java standard which is being developed through Java Community Process (JCP). Several prominent tool vendors are members of the group and are committed to provide easy to use, visual, and productive develop environments for JavaServer Faces.

An extensible architecture:

JSF architecture has been designed to be extensible.Extensible means additional functionality can be given on the top of JSF core i.e. we can customize the functionality. JSF UI components are customizable and reusable elements. You can extend standard components and create your own complex components like stylish calendar, menu bar etc.

Support for multiple client devices:
Component developers can extend the component classes to generate their own component tag libraries to support specific client. JSF flexible and extensible architecture allows developers to do so.

Flexible rendering model:
Renderer separates the functionality and view of the component. So we can create multiple renderers and give them different functionality to get different appearance of the same component for the same client or different .

International language support:
Java has excellent support for internationalization . It allows you to localize messages with user specific locale. A locale is a combination of a country, a language, and a variant code. JavaServer Faces adopts this property and let you specify which locale your application supports. So you can display you messages in different languages.

Robust tool support:
There are several standard tool vendors like Sun Java Studio Creator who provide robust tools that take advantages of JSF to create server side UI easily.

source: roseindia.net

Friday, August 08, 2008

JSF Features

JSF is a rich featured framework of JAVA technology. JSF provides a set of standard features that makes it a powerful and standard among the existing technologies available for the development of web application based on java technologies. Some of the features have been given below to justify the above statement.

  1. JSF is standard web user interface framework for Java.
  2. Built on top of Servlet API.
  3. JSF is a component framework
  4. UI components are stored on the server.
  5. Easy use of third party components.
  6. Event driven programming model.
  7. Events generated by user are handled on the server.
  8. Navigation handling.
  9. Can automatically synchronize UI components .
  10. JSF supports multiple client devices.
  11. JSF has extensible architecture.
  12. International language support.
  13. Extensive tool support (Sun, Oracle , IBM etc.).
  14. Rapid application development approach.

A short view of jsf features has been given above. Its main features are component model, event driven, extensible architecture, rapid application development. All of the features will be described in subsequent topics.

source: roseindia.net

Thursday, August 07, 2008

JSF Versions

JSF started its journey from version 1.0 and now it has come to the latest version of JSF is 1.2. The listing of versions released so far are :

  1. JSF 1.2 (11 may 2006) - Latest release of JSF specification.
  2. JSF 1.1 (27 may 2004) - Bug fix release. No specification changes. No HTML renderkit changes.
  3. JSF 1.0 (11 mar 2004) - Initial release of JSF specification.

There are many releases of 1.1 and 1.2 and these are listed below showing released date also:

  1. 1.2_04 P01 (20 Mar 2007)
  2. 1.2_04 (5 Mar 2007)
  3. 1.2_02 (25 Aug 2006)
  4. 1.2_01 (14 July 2006)
  5. 1.1_02 (24 Apr 2006)
  6. 1.1_01 (07 Sep 2004)

The JSF specification was developed under the Java Community Process (JCP) as JSR 127, which released JSF 1.0 and 1.1, and JSR 252 which released JSF 1.2. The first release of JSF is JSF 1.0 in 2004. JSF 1.0 supports servlet 2.3 and jsp 1.2. After JSF 1.0, JSF 1.1 was released. The main purpose of this release was bug-fixing. There were no specification or HTML renderkit changes. This version also works with same version of servlet 2.3 and jsp 1.2 as in the case of JSF 1.0.

JSF 1.1_01 release features bug fixes and performance improvements. Improvements include compression of views serialized to the client, failover support when storing views on the server, renderer fixes, and several other bug fixes and enhancements.It supports JDK 1.3.1 or later. Many bugs have been fixed so if your application depends on one of these bugs, it needs to be changed.

JSF 1.2 is the latest release and it works with servlet 2.5 and jsp 2.1. If you want to run JSF 1.2 on Tomcat, you want 6.0 not 5.5. So JSF needs a web container that supports atleast servlet 2.3 and jsp 1.2 and these are part of J2EE 1.3.

New in JSF 1.2

In this section we will go through some new features and changes in JSF 1.2 specification. JSF 1.1 was designed for JSP 1.2 and so could not take advantage of newer JSP features and JSP could not be changed to fill the needs of JSF. This resulted in a number of new features and changes. For ex.

  1. Unified Expression Language(EL) :
    Unified EL has been added to JSTL to overcome problems when integrating JSP EL with the JSF EL.EL was used to access data objects in a simple way. It is used mainly as a short-hand for accessing values. Later it was included in JSP 2.0 with more functionality.When JSF was released it also needed EL.JSF and JSP each has its own EL.The JSP EL is much flexibile to the web application developer but JSF people were unsatisfied by the JSP EL.One of the reason was that it requires JSP engine to evaluate expression at the appropriate time during the lifecycle, but JSP expressions are evaluated immediately. The second reason behind it was that JSP functions could only call static methods in TLD and they cannot be used to invoke public methods dynamically on server side objects during lifecycle to validate data and handle component evevts.
    So these were the reasons for developing such an EL that would work for both JSP and JSF and make using JSP and JSF together easier. This new EL is called unified EL. So this was inspired by EL used in JSTL and JSP. There is a package "el" in javax package that represents EL.

    In addition to the features already available in the JSP EL, unified EL has the following features :
    1. Deferred evaluation of expressions i.e.evaluation of the expression at the appropriate time during the page lifecycle from JSP engine.
    2. Support for expressions that can set and get values
    3. Support for expressions that can invoke methods.
    4. A pluggable API for resolving expressions
  2. Ajax Support :
    JSF framework can make things a little easier to write AJAXian JSF components.JSF allows to map different instances of the FacesServlet with different lifecycles.For example, one mapping for standard JSF requests and another for AJAX JSF requests.
  3. New Tree Creation and Content Interweaving Model for Faces applications that use JSP :
    We can make JSF application without using any JSP page but it can also be developed using both JSP and JSF.Using JSP makes some developers easy to handle.Sometimes When integrated it did not respond as we expect. These problems have been resolved in JSF 1.2.There have been made some changes in specification of the implementation of the FacesViewHandler for JSP and JSP custom tag base class.
  4. Integration with JSTL :
    Using JSTL's tag to contain Faces input components was one of the problem, because JSP has no notion of a postback, it was not possible to apply the values correctly to the nested input components on postback. Some new concepts in EL make it possible to use this tag fully with any kind of JSF component.
  5. Back Button issues and Multi Frame or Multi Window Faces Apps :
    JSF have fixed the problem related to Multi Frame or Multi Window applications.The browser back button also created some problems. These problems were because of deficiency in the State Management API.
  6. Associating a message with a particular component in the page :
    Previously we could not include label of a component dynamically in an error message for that component. Now it's possible in new JSF 1.2.It's also possible to override the conversion or validation message that is displayed to the user on a per-instance basis.
  7. Expose an application wide ResourceBundle to the EL :
    element in faces-config allows listing many resource bundles that should be exposed to the EL using the new ELResolver chain.This optimize performance and prevent the need to create a ResourceBundle for every request.
  8. Use of multiple renderKits.
  9. Provide XML Schema for the config files, instead of using DTD.
  10. Security enhancements for client side state saving.
  11. Solve the "duplicate button press" problem.
  12. The portlet related bug-fixes.

JSP 2.1 is developed under JSR-245 and JSF 1.2 is developed under JSR-252. These two groups have experts and they are working independently but the main focus of development was to provide more support and compatibility between these two technology that are powerful web presentation technology so that they can be useful for each other.

source: roseindia.net

Tuesday, August 05, 2008

What is JSF?

In this section "What is JSF?" you will get detailed overview of JSF technology, which is ready to revolutionize the web application development process. JSF is complex system but you will be highly benefited by JSF technology. For example, you can easily make rich graphical Web application that can't be easily developed in HTML. Here we have tried to explain the JSF in easily understandable manner so that beginner can also understand easily.

What is JSF?

JSF is new standard framework, developed through Java Community Process (JCP), that makes it easy to build user interfaces for java web applications by assembling reusable components in a page. You can think of JSF framework as a toolbox that is full of ready to use components where you can quickly and easily add and reuse these components many times in a page and capture events generated by actions on these components. So JSF applications are event driven. You typically embed components in a jsp page using custom tags defined by JSF technology and use the framework to handle navigation from one page to another. Components can be nested within another component , for example, input box, button in a form.

JSF is based on well established Model-View-Controller (MVC) design pattern. Applications developed using JSF frameworks are well designed and easy to maintain then any other applications developed in JSP and Servlets.

JSF eases the development of web applications based on Java technologies. Here are some of benefits of using JSF:

  • JSF provides standard, reusable components for creating user interfaces for web applications.

  • JSF provides many tag libraries for accessing and manipulating the components.

  • It automatically saves the form data and repopulates the form when it is displayed at client side.

  • JSF encapsulates the event handling and component rendering logic from programmers, programmers just use the custom components.

  • JSF is a specification and vendors can develop the implementations for JSF.

  • There are many GUIs available these days to simplify the development of web based application based on JSF framework.

JSF Components

JSF includes mainly:

  1. Set of APIs to represent and manage state of components that helps server side validation, event handling, page navigation, data conversion etc.
  2. JSP custom tag library to create UI components in a view page.
The UI (user interface) created using JSF technology runs on server and output is shown to the client. Goal of JSF is to create web applications faster and easier. Developers can focus on UI components, events handling, backing beans and their interactions rather than request, response and markup. JSF hides complexities to enable developers to focus on their own specific work.

source: roseindia.net

Monday, August 04, 2008

JSF Overview

The quick Overview of JSF Technology

This section gives you an overview of Java Server Faces technology, which simplifies the development of Java Based web applications. In this JSF overview section you will learn how JSF fits into the web application development landscape.

JSF was developed by Java Community Process(JCP). This is a community of web application experts. These experts are from different groups like Jakarta Struts, Oracle, Sun, IBM, ATG etc. They all collectively worked together to take the best from existing technologies and removed problems. So their collective effort brought a new technology named Java Server Faces (JSF).

Java Server Faces or JSF for short, is the standard framework to simplify the process of developing web application in java. It is a robust component framework, event driven programming model. It offers a set of UI components, extensible architecture, supports multiple client devices etc. Extensible means additional functionality can be given on the top of JSF core i.e. we can customize the functionality. JSF is vendor independent technology that is a standard to be supported by whole software industry.

One of the main feature of JSF is that it has not only been designed for coding experts but for others also like :

  1. Page authors
    Web designers have experience with graphic design. They can design look and feel of web application in html/jsp using custom tag libraries of JSF.
  2. Application developers
    Application developers can integrate this design with UI components. They program objects, event handles, converters, validators.
  3. Component writers
    Component developer can build custom UI components because of JSF’s extensible and customizable nature. They can create their own components directly from UI component classes or extending the standard components of JSF.
  4. Application architects
    Application architects are responsible for designing web applications. Defining page navigation, ensuring Scalability of application, configuring beans object registration are the key points that an application architect handles.
  5. Tool vendors
    JSF is well suited for tool vendors, for example Sun Java Studio Creator application development tool, who provide tools that take advantages of JSF to create UI easier.

In the past many web development frameworks came in to existence founded on servlet and jsp. Struts emerged as a standard web application framework. It became framework of choice because it came early in the market and provided necessary features at the time but competitors continued providing additional features that struts lacks. So it became necessary for java to advent new standard framework with a powerful component model. This was the reason for developing JSF technology. So main purpose of developing JSF was to create a collection of APIs for the UI components with the capacity to manage their states, handle events and validation.

Struts has an option to migrate to JSF. The simplest option is to use JSF components and rest as usual. This will enable them to take advantage of third party JSF components. Main feature of JSF is ease of use. Developing web applications is easier and faster than other frameworks like struts because JSF supports UI components and easy event handling. Taking advantages of third party components can reduce the cost of rewriting existing elements, minimize the time of development.


source: roseindia.net