Wednesday, March 08, 2006

JSF notes on event handling

Three different kinds of listeners:
  • Phase listener -- listener is invoked as jsf goes through each of the 6 phases, you can register for a specific phase or all of them.
  • Action listener -- listener is invoked when an action like command button is clicked.
  • Vlaue change listener -- listener is invoked when an input component like textbox value is entered and form submitted
There is subtle difference between the use of action handlers and action listeners, handlers are meant for business rules, iterfacging with backend systems, and
navigational logic whereas listeners are meant to handle with UI elements only.

Action listeners are invoked before action handlers.

Value change and action listeners can be added as UI element attibutes as well as tags. It is better to add as tags.

Below are the execution of different phases for different scenarios:
  • value change listener --> 1 -- 2 -- 3 (listener called) -- (4 -- 5 -- 6)
  • value change listener with immediate --> 1 -- 2 (listener called) -- 3 -- (4 -- 5 -- 6)
  • action listener --> 1 -- 2 -- 3 -- 4 -- 5 (listener called) -- (6)
  • action listener with immediate --> 1 -- 2 (listener called) -- (6)

JSF General Notes

Some notes from the core jsf servlets book.

  • value binding expressions, eg., "#{....}". property getter is invoked when the component is rendered and setter is invoked when when the user response is processed.
  • method binding expressions
  • JSF connects the view and model
  • each ui tag is associated with a tag handler. tag handlers collaborate with each other to build a component tree (not necessarily binary tree)
  • encoding is when the renderer of a component generated the output. eg., html output
  • decoding is when the html elements are processed by JSF container to do things like update component values, navigation, etc.
  • six life cycle steps: restore view, apply request values, process validations, update model values, invoke application, render response
  • action methods have 2 roles, first carry out the model updates and second tell the navigational handler where to go next
  • action method can return null to indicate that the same page should be redisplayed
  • all form controls (ui elements like textbox, etc) generated by JSF have names that conform to formName:componentName. if you do not specify id attributes, jsf framework creates automatically
  • DataTable : The body of h:dataTable tags can contain only h:column tags and all the other component tags are ignored.
  • DataTable: value attribute can be set to an array, List, ResultSet, javax.servlet.jsp.jstl.sql.Result, javax.faces.model.DataModel
  • DataTable: h:dataTable wraps objects in a model that extends the javax.faces.model.DataModel class which provides apis like getWrappedObject() and setWrappedObject() which can be used to add/remove table rows.
  • Conversion: this happens in the "apply request values" phase where the string values submitted as part of form is converted to appropriate objects.
  • Conversion:
  • <meta http-equiv="Refresh" content= "0; URL=index.faces"/>