Exonerating the JSF Lifecycle

One of the many accusations aimed at JSF is the definition and complexity of the JSF Lifecycle. The JSF lifecycle is responsible for processing the page creation and submission and orchestrates the different pieces of the framework. A more thorough description of the process can be found in this article by Rick Hightower. At a high level, this process is defined as :

  1. Restore View – JSF builds the view for the first time or restores the component tree.
  2. Apply Request Values – take the values from the submitted form, convert them and put them in the component objects.
  3. Process Validation – validates the converted values based on applicable validators. If validation fails, we jump to the last step.
  4. Update Model Values – take the converted and validated values and put them in the properties of the backing bean.
  5. Invoke Application – Once your backing beans have been updated, the application is called and usually code is executed against the backing beans.
  6. Render Response – the response is generated and sent back to the users browser.

It is claimed that it is an unnecessary complexity that the developers must deal with in order to use JSF. Understanding the lifecycle is not a requirement but will help you understand what is going on, but what is objectionable about this assertion is that this lifecycle is no different than just about any other web framework. One Spring MVC user has posted a cheat sheet which is quite a handy guide to the form controller. It shows how complex Spring MVC can be in executing identical behavior. Wicket and even ASP.net perform the same steps in that it utilizes a server side model, pushes the values in, converts and validates them, handles events, and then renders a response. Even the most simplistic frameworks must always extract values, convert and validate them since when working in the web, you are merely pushing strings between server and client. At some point these string values be converted to meaningful data and objects and the consequences of invalid content must be dealt with. JSF is quite upfront about this process and even lets you hook in to the lifecycle events through the JSF PhaseListener.

Comments are closed.