com.davesag.jsf
Class AbstractReadWriteHandler

java.lang.Object
  extended bycom.davesag.jsf.AbstractContextAwareBean
      extended bycom.davesag.jsf.AbstractHandler
          extended bycom.davesag.jsf.AbstractReadWriteHandler
All Implemented Interfaces:
Handler, ReadWriteHandler

public abstract class AbstractReadWriteHandler
extends AbstractHandler
implements ReadWriteHandler

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

ReadWriteHandlers correspond to the controller component of the MVC pattern.

Version:
CVS Revision $Id:$

Field Summary
 
Fields inherited from class com.davesag.jsf.AbstractHandler
CANCEL, ERROR, SUCCESS, theFields, theItem
 
Constructor Summary
AbstractReadWriteHandler()
           
 
Method Summary
 String create()
          Makes a new instance of the bean to be handled.
 String delete()
          deletes the current item.
protected abstract  void deleteItem(Object model)
          deletes the item from a persistent store.
protected abstract  Object instantiateItem()
          If permitted, this method should create a new default item.
 String release()
          releases the current item without saving.
 String save()
          Saves the item.
protected abstract  Object saveItem(Object model)
          saves the item to a persistent store.
protected abstract  Object viewToModel(Map view, Object model)
          populate the supplied object with data from the view's fields map.
 
Methods inherited from class com.davesag.jsf.AbstractHandler
clear, getFields, getItem, isActive, load, loadById, modelToView, view
 
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
 
Methods inherited from interface com.davesag.jsf.Handler
getFields, getItem, isActive, load
 

Constructor Detail

AbstractReadWriteHandler

public AbstractReadWriteHandler()
Method Detail

instantiateItem

protected abstract Object instantiateItem()
                                   throws Exception
If permitted, this method should create a new default item. If it can not then return null and be sure that you deal with this situation in viewToModel(java.util.Map, java.lang.Object) and AbstractHandler.modelToView(java.lang.Object, java.util.Map).

Returns:
the instatiated object, or null. If null then the underlying object must be built in the first pass of viewToModel.
Throws:
Exception - if anything bad happens.

saveItem

protected abstract Object saveItem(Object model)
saves the item to a persistent store.

Parameters:
model - The object you wish to save.
Returns:
the saved object.

deleteItem

protected abstract void deleteItem(Object model)
                            throws Exception
deletes the item from a persistent store.

Parameters:
model - The object you wish to delete.
Throws:
Exception - if anything went wrong.

viewToModel

protected abstract Object viewToModel(Map view,
                                      Object model)
populate the supplied object with data from the view's fields map. 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 you can now construct the object using the values supplied. The need for this could be minimised by correct use of JSF Converters. Thought - should this throw a javax.faces.ConverterException?

Parameters:
view - The map of properties captured from the user interface.
model - The object to populate based on values in the view.
Returns:
the newly populated object, or null if there was a mapping error.

create

public String create()
Makes a new instance of the bean to be handled.

Specified by:
create in interface ReadWriteHandler
Returns:
a result code.

save

public String save()
Saves the item. If it doesn't have an id, then it will get one when it is saved.

Specified by:
save in interface ReadWriteHandler
Returns:
a result code.

release

public String release()
releases the current item without saving. this is an exit point for the handler. after release is called there is no current item.

Specified by:
release in interface ReadWriteHandler
Returns:
a result code.

delete

public String delete()
deletes the current item. this is an exit point for the handler. If there was any error trying to delete the current item then this method will still act as an exit point. In all circumstances after delete is called there is no current item.

Specified by:
delete in interface ReadWriteHandler
Returns:
a result code.


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