com.davesag.jsf
Class AbstractHandler

java.lang.Object
  extended bycom.davesag.jsf.AbstractContextAwareBean
      extended bycom.davesag.jsf.AbstractHandler
All Implemented Interfaces:
Handler
Direct Known Subclasses:
AbstractReadWriteHandler

public abstract class AbstractHandler
extends AbstractContextAwareBean
implements Handler

The AbstractHandler is a base class for you to develop your own handler Managed Beans. To implement a specific handler for your own data types simply fill in the methods to do the following:

Handlers correspond to a read only controller component of the MVC pattern.

Version:
CVS Revision $Id:$

Field Summary
static String CANCEL
          cancel indicates the user released the item without saving.
static String ERROR
          error indicates an error occured
static String SUCCESS
          success indicates that the action was performed okay
protected  Map theFields
          A Map of Public facing properties that are referenced by the JSF tags.
protected  Object theItem
          The object being handled by this handler.
 
Constructor Summary
AbstractHandler()
          Default Constructor that resets the map and item.
 
Method Summary
protected  void clear()
          resets the active item back to null and the form fields map to empty;
 Map getFields()
          Gets the map containing form fields
 Object getItem()
          gets the item.
 boolean isActive()
          is there currently a bean being handled?
 String load()
          Loads the item with an id obtained from the request string.
protected abstract  Object loadById(Object id)
          Loads the item with the given an id.
protected abstract  Map modelToView(Object model, Map view)
          populate a field map with data from an object.
 String view()
          an alias for load().
 
Methods inherited from class com.davesag.jsf.AbstractContextAwareBean
addMessage, getContext, getMessageBundleName, getRequestParameter, getServletContext, getSession
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR

public static final String ERROR
error indicates an error occured

See Also:
Constant Field Values

CANCEL

public static final String CANCEL
cancel indicates the user released the item without saving.

See Also:
Constant Field Values

SUCCESS

public static final String SUCCESS
success indicates that the action was performed okay

See Also:
Constant Field Values

theItem

protected Object theItem
The object being handled by this handler. It corresponds to the model in the MVC pattern.


theFields

protected Map theFields
A Map of Public facing properties that are referenced by the JSF tags. It corresponds to the view in the MVC pattern.

Constructor Detail

AbstractHandler

public AbstractHandler()
Default Constructor that resets the map and item. Handlers are designed to be session managed beans under a JSF framework. Hence they are only constructed once and then repeatedly cleared.

Method Detail

loadById

protected abstract Object loadById(Object id)
                            throws Exception
Loads the item with the given an id. Override this to implement your own handlers.

Parameters:
id - The unique id, or query object of the obejct/s you wish to load.
Returns:
the saved object or a collection of query results.
Throws:
Exception - if anything bad happens.

modelToView

protected abstract Map modelToView(Object model,
                                   Map view)
populate a field map with data from an object. If the underlying object is null then this may be because the constructor for that object requires some as yet unset properties. In this case populate the view with default values. The need for this could be minimised by correct use of JSF Converters. Thought - should this throw a javax.faces.ConverterException?

Parameters:
model - The object whose data you wish to map to the view.
view - The map of properties captured from the user interface.
Returns:
a Map of properties for presentation to the user interface.

getFields

public Map getFields()
Gets the map containing form fields

Specified by:
getFields in interface Handler
Returns:
the Map containing form fields

isActive

public boolean isActive()
is there currently a bean being handled?

Specified by:
isActive in interface Handler
Returns:
true if there is a currently handled bean. (ie have we got a fields map with anything in it);

getItem

public Object getItem()
gets the item.

Specified by:
getItem in interface Handler
Returns:
the currently handled bean. or null if there is no bean being handled.

load

public String load()
Loads the item with an id obtained from the request string.

Specified by:
load in interface Handler
Returns:
a result code.

view

public String view()
an alias for load().


clear

protected void clear()
resets the active item back to null and the form fields map to empty;



JSF Helper API version 20 Jan 2005. (C) 2004 Dave Sag.