br.com.arsmachina.tapestrycrud.base
Class BaseEditPage<T,K extends Serializable>

java.lang.Object
  extended by br.com.arsmachina.tapestrycrud.base.BasePage<T,K>
      extended by br.com.arsmachina.tapestrycrud.base.BaseEditPage<T,K>
Type Parameters:
T - the entity class related to this encoder.
K - the type of the class' primary key property.
All Implemented Interfaces:
CrudPage<T,K>, EditPage<T,K>

@Meta(value="tapestry.persistence-strategy=flash")
public abstract class BaseEditPage<T,K extends Serializable>
extends BasePage<T,K>
implements EditPage<T,K>

Base class for pages that edit entity objects. One example of its use can be found in the Ars Machina Project Example Application (page class. template).

Author:
Thiago H. de Paula Figueiredo

Constructor Summary
BaseEditPage()
          Single constructor of this class.
 
Method Summary
protected  void addError(String fieldId, String message)
          Adds an error to a given field in the form.
 void clearObject()
          Sets the object to null.
protected  T createNewObject()
          Creates a new entity object to be edited.
protected  Form getForm()
          Returns the value of the form property.
protected  BaseListPage<T,K> getListPage()
          Returns the BaseListPage instance associated to this object.
 T getObject()
          Returns the value of the object property.
 String getZone()
          Returns null if we are inserting a new object and #DEFAULT_FORM_ZONE_ID (zone) otherwise.
 Object onPassivate()
          Returns the current activation context of this page.
protected  void prepare()
          Ensures the edited object is not null before form rendering and submission.
protected  void prepareObjectForSaveOrUpdate()
          Does any processing that must be done in the object before it is saved or updated.
protected  Object returnFromRemove()
          Defines what saveOrUpdate() will return and sets the success message.
 Object saveOrUpdate()
          Saves or updates the edited object.
 void setObject(T object)
          Changes the value of the object property.
protected  void setSaveOrUpdateSuccessMessage()
          Sets the save or update success message in this page.
protected  Object validate()
          Validates the object.
protected  void validateObject(T object, Form form)
          Validates an object and stores the validation erros in a form.
 
Methods inherited from class br.com.arsmachina.tapestrycrud.base.BasePage
filterReadOnlyComponentsInBeanModel, getActivationContextEncoder, getController, getEntityClass, getFormZone, getLabelEncoder, getMessage, getMessages, getPrimaryKeyClass, getPrimaryKeyEncoder, getSelectModelFactory, getValueEncoder, returnZoneOnXHR, setMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface br.com.arsmachina.tapestrycrud.EditPage
getFormZone
 
Methods inherited from interface br.com.arsmachina.tapestrycrud.CrudPage
getEntityClass, getMessage, getPrimaryKeyClass, setMessage
 

Constructor Detail

BaseEditPage

public BaseEditPage()
Single constructor of this class.

Method Detail

prepare

@OnEvent(component="form",
         value="prepare")
protected final void prepare()
Ensures the edited object is not null before form rendering and submission. It uses createNewObject() to create a new entity object if needed. If not, getController.reattach(object) is invoked.

See Also:
ReadableController.reattach(Object)

validate

@OnEvent(component="form",
         value="validateForm")
protected final Object validate()
Validates the object. This method invokes #validateObject(Form) and then takes care of handling AJAX form submissions.


validateObject

protected void validateObject(T object,
                              Form form)
Validates an object and stores the validation erros in a form. This implementation does nothing.

Parameters:
object - an #T.
a - Form.

addError

protected final void addError(String fieldId,
                              String message)
Adds an error to a given field in the form.

Parameters:
fieldId - a String. It cannot be null.
message - a String. It cannot be null.

saveOrUpdate

@OnEvent(component="form",
         value="success")
public final Object saveOrUpdate()
Saves or updates the edited object. This method does the following steps:
  1. Invokes prepareObjectForSaveOrUpdate()
  2. .
  3. Invokes BasePage.getController().saveOrUpdate(entity);.
  4. Invokes and returns returnFromRemove()


returnFromRemove

protected Object returnFromRemove()
Defines what saveOrUpdate() will return and sets the success message.

Returns:
an Object or null.

setSaveOrUpdateSuccessMessage

protected void setSaveOrUpdateSuccessMessage()
Sets the save or update success message in this page.


getListPage

protected BaseListPage<T,K> getListPage()
Returns the BaseListPage instance associated to this object. This is used by #returnAfterAction() to define what will be returned by saveOrUpdate(). This implementation returns null and must be overriden by pages that want to show the listing page after a successful save or update.

Returns:
a BaseListPage.

prepareObjectForSaveOrUpdate

protected void prepareObjectForSaveOrUpdate()
Does any processing that must be done in the object before it is saved or updated.


createNewObject

protected T createNewObject()
Creates a new entity object to be edited. Fields can be prefilled if desired. This method is used by prepare(). This implementation attempts to instantiate the object using its class default constructor.

Returns:
a T.

getObject

public T getObject()
Returns the value of the object property.

Specified by:
getObject in interface EditPage<T,K extends Serializable>
Returns:
a T.

setObject

public void setObject(T object)
Changes the value of the object property.

Specified by:
setObject in interface EditPage<T,K extends Serializable>
Parameters:
object - a T.

getForm

protected final Form getForm()
Returns the value of the form property.

Returns:
a Form.

onPassivate

public final Object onPassivate()
Returns the current activation context of this page.

Returns:
an #A.

getZone

public String getZone()
Returns null if we are inserting a new object and #DEFAULT_FORM_ZONE_ID (zone) otherwise.

Returns:
a String.

clearObject

@OnEvent(value="newObject")
public final void clearObject()
Sets the object to null.



Copyright © 2008-2009 Thiago H. de Paula Figueiredo. All Rights Reserved.