Tuesday, March 27, 2007

Spring's IoC

Spring Framwork is promoting loose coupling through a inversion of control (IoC). A powerful idea. When IoC is applied, objects are passively given their dependencies instead of creating or looking for dependent objects for themselves. This defers the architectural decisions to be taken at later point of time. In other terms, my class need not know what kind of implementation being injected by framework. The injected object can be remote object or local object. It could be a web service, EJB or an RMI object.

Sunday, March 25, 2007

JSF Lifecycle

JSF Lifecycle Phases

1. Restore View

- If the request is first visit of page, builds the view of the page, wire event handlers and validator to each component in view and saves view in FacesContext

- If the action is post back, it restores the view which had already been created

2. Apply request values

- Recursively calls decode() on all the components in tree by extracting new values from request

- In case of conversion failure, stacks up error messages in faces context

- If there are any events queued up, notifies the interested listeners

- If any of the components have immediate attribute set to 'true', conversion, validation and events associated with component are done in this phase

- If the redirection to another web app or non-JSF page required, responseComplete() called on FacesContext

- If the validators or listeners call FacesContext’s renderResponse method, the lifecycle skips to render response phase.

3. Process Validations
- Registered validators on components triggered and error messages would be stacked into faces context if there are any validation issues

- If there are any events queued up, notifies the interested listeners

- If the redirection to another web app or non-JSF page required, responseComplete() called on FacesContext

- If the validators or listeners call FacesContext.renderResponse method, the lifecycle skips to render response phase.

4. Update model values phase

- Copies the values to backed bean properties

- In case of conversion issues, lifecycle advances to render response phase

- If the updateModels or listerners call FacesContext.renderResponse method, the lifecycle skips to render response phase.

- If there are any events queued up, notifies the interested listeners.

- If the redirection to another web app or non-JSF app required, responseComplete() called on FacesContext
- Invoke Application Phase

5. Handles the application level events

- If the redirection to another web app or non-JSF app required, responseComplete() called on FacesContext

6. Render Response Phase

- Renders the response

- If there are any validation errors, renders the error messages on page if there are messages tags.

Saturday, March 24, 2007

Coding with JSF is more OO

JSF is giving opportunity to make the code much more object oriented in web technology. While working with Struts, I used to feel like I am working with data and behavior in two different classes i.e. Form Beans and Action classes. It gives you a feel of you are doing the code in traditional procedural programming languages

With JSF, managed beans concept is removing the extra class and giving flexibility to write the data and behavior in same class.