Saturday, December 8, 2007

JSF Overview

The UIComponentBase class is the base class for all JSF UI components. Subclasses represent specific interface elements, such as text fields, links and buttons, labels, menus and selection lists.

The components fire events in response to user actions (such as clicking a button) and event listeners attached to the components handle the events (for example, by updating a database). Instead of implementing and registering listeners for each component, most JSF applications take advantage of shortcuts in the form of method bindings. A method binding is similar to a value binding, but it binds a component to an application method instead of an application property value. For instance, the UICommand component has a property that takes a method binding value. When the component fires an ActionEvent, a default ActionListener provided by JSF and automatically attached to the component invokes the method that the method binding points to. All the component writer needs to do is implement the method.

but declaring the scope as session (or others) means that a unique instance is created for each user and remains available as long as the user actively uses the application

Elements with the prefix h (short for HTML) represents the standard JSF UI components combined with HTML renderers; elements with the prefix f (short for Faces) represent validators, event listeners, etc. that can be attached to the UI components

The basic hierarchy is and inside it is

When JSP page is invoked for first time then
< h : inputText value="#{abc.emailID}" / >
i) the corresponding UIInput element is created
ii) Its property value bound to the bean value specified by the binding expression
iii) component is asked to render itslef ... i.e. renderer called !
iv) It evaluates value binding expression and if bean doesnt exist ( based on scope ) then JSF creates it!
v) The input component pulls its value from the property of the bean specified by the rest of the value binding expression and uses it as the value of the HTML < input > element it renders

When the user enters values in the form and clicks the Submit button, JSF processes the request by asking each component to get its value from the request .. so basically JSF doesnt talk to HTTPRequest .. but components ... Each input component sets the bean property it's bound to, and the command component fires an event that causes the method it's bound to be invoked. The method typically saves the new values to a database or does some other backend processing.

This is a very simplified description of what really occurs at runtime. As you will learn, there's a lot more that may happen when a form is submitted, such as input value conversion and validation, error message queuing, forced redisplay of the same page without updating any bean properties, and more. simple description helps understand understand the basics of how the application code and the JSF components fit together.

No comments: