Q. Explain briefly the life-cycle phases of JSF?


1. Restore View :
A request comes through the FacesServlet controller. The controller examines the request and extracts the view ID, which is determined by the name of the JSP page


2. Apply request values:
The purpose of the apply request values phase is for each component to retrieve its current state. The components must first be retrieved or created from the FacesContext object, followed by their values.Values provided in components that hold a value (such as input fields) have their values applied to their counterparts in the view tree. All events such as ValueChangeEvents (VCE) or ActionEvents (AE) are queued. A VCE means that a value has changed for a specific UI component. An AE means that a button (or any UI component that is a source of an action) was clicked. If a component has its immediate attribute set to true, then validation, conversion, and events associated with the component are processed during this phase.

3. Process validations: In this phase, each component will have its values validated against the application’s validation rules.Conversion and validation logic is executed for each component. This means both built-in validation/data conversion and custom validation/conversion are added onto the components. If a validation error is reported, an exception is thrown. The life cycle halts and the response is rendered with validation error messages. At the end of this phase, new component values are set, any validation or conversion error messages and events are queued on FacesContext, and any value change events are delivered.

4. Update model values: In this phase JSF updates the actual values of the server-side model ,by updating the properties of your backing beans.The component’s validated local values are moved to the model and the local copies are discarded. If you are using a backing bean for a JSF page to manage your UI components, any managed bean properties that are value-bound to the UI component using the value attribute are updated with the value of the component

5. Invoke application: In this phase the JSF controller invokes the application to handle Form submissions.

6. Render response: In this phase JSF displays the view with all of its components in their current state.Any action bindings for command components or events are
invoked. Navigation is handled here depending on the outcome of action method (if any).

Understanding the JSF Immediate Attribute

As, i am working on my project.I have to use cancel button.So somebody said make immediate attribute to true.There is very common myth among ADF and JSF developers that using Immediate attribute will avoid unnecessary validation in any case. It is not 100% correct. Basically , everyone not very much clear about it. If we don’t use correctly , application can work randomly.Let discuss more about it to have better understanding.

In ADF application we have either

1. input component
2. Command component

You can use the immediate attribute to allow components on the page to be validated in the Apply Request Values phase of the life cycle as opposed to the Process Validations phase:

•Input component- Using immediate on an means that that component’s value is validated before any input components that do not have the immediate attribute set to true. Therefore, if a validation error occurs on an immediate input component, the life cycle moves from the Apply Request Values phase (where the immediate attribute is evaluated) to the render phase, and validation does not run on any “nonimmediate” input components. Additionally, if the new value of an immediate input component is different from the existing value, then a ValueChangeEvent is raised. However, instead of the event being processed during the Process Validations phase, the event is processed at the end of the Apply Request Values phase. Therefore, any ValueChangeListener associated with the immediate input component executes before any command component’s ActionListener (assuming the command component occurs later on the page).


• Command Components-
if set to immediate and the component has an action that
returns a value for navigation, the life cycle proceeds directly to the Render Response
phase. The validation and model update phases are skipped. A Cancel button is an example of when this would be used

Interfaces in Hibernate

There are 5 main Interfaces in Hibernate which form its lifeline. All of them are found in the org.hibernate package. An overview of the hibernate APIs can be found at www.hibernate.org

• Configuration interface

o Used to configure hibernate in any java application
o The java application is provided with a JDBC connection and resource mapping using the Configuration API
o It’s the first object a user uses while working with hibernate

• SessionFactory interface

o This interface is used to obtain session objects
o Though it is thread safe, we need one SessionFactory for each database that the application is connecting to.
o It acts as a kind of Cache storage during runtime giving the database sessions available for java objects.

• Session interface

o This is the primary Interface used by hibernate
o It is known as the hibernate’s persistence manager
o It is the interface used to obtain a transaction.
o It is different from the httpSession object and the two should not be confused.
o Session objects are not thread safe

• Transaction interface

o Though an optional API, it performs the all important task of abstracting the application from the underlying complex JDBC or JTA transaction.
o Each transaction object represents an atomic unit of work.
o Each session may have one or more transactions.

• Criteria and Query interface

o Query interface controls the “how” and “what” of executing queries on a database.
o Queries can be written in native SQL or in hibernate query language
o Criteria queries are those created using Java objects and Criteria interface is useful in helping to create them.