|
Version 4.10.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object hirondelle.web4j.action.ActionImpl hirondelle.web4j.action.ActionTemplateListAndEdit
public abstract class ActionTemplateListAndEdit
Template for "all-in-one" Action
s, which perform
common operations on a Model Object.
Typically a single JSP is used, for displaying both a listing of Model Objects, and an accompanying form for editing these Model Objects one at a time. This style is practical when :
The SupportedOperation
s for this template are a subset of the members of the
Operation
enumeration. If other operations are desired, then this template class cannot be used.
This class interacts a bit with its JSP - the form changes from "Add" mode to "Change" mode
according to the value of the Operation
.
If an operation is not appropriate in a given case, then simply provide an empty implementation of
its corresponding abstract method (or an implementation that throws an
UnsupportedOperationException
).
To communicate messages to the end user, the implementation must use the various addMessage and addError methods.
Field Summary | |
---|---|
static RequestParameter |
SupportedOperation
The operations supported by this template. |
Fields inherited from class hirondelle.web4j.action.ActionImpl |
---|
DATA, ERRORS, ITEM_FOR_EDIT, ITEMS_FOR_LISTING, MESSAGES, USER_ID |
Constructor Summary | |
---|---|
protected |
ActionTemplateListAndEdit(ResponsePage aForward,
ResponsePage aRedirect,
RequestParser aRequestParser)
Constructor. |
Method Summary | |
---|---|
protected void |
addDynamicParameterToRedirectPage(String aParamName,
String aParamValue)
Add a dynamic query parameter to the redirect ResponsePage . |
protected abstract void |
attemptAdd()
Attempt an INSERT operation on the database. |
protected abstract void |
attemptChange()
Attempt an UPDATE operation on the database. |
protected abstract void |
attemptDelete()
Attempt a DELETE operation on the database. |
protected abstract void |
attemptFetchForChange()
Attempt to fetch a single Model Object from the database, in preparation for editing it (SELECT operation). |
protected abstract void |
doList()
Retrieve a listing of Model Objects from the database (SELECT operation). |
ResponsePage |
execute()
Template method. |
protected abstract void |
validateUserInput()
Validate items input by the user into a form. |
Methods inherited from class hirondelle.web4j.action.ActionImpl |
---|
addError, addError, addError, addMessage, addMessage, addToRequest, addToSession, copyFromSessionToRequest, createSessionAndCsrfToken, endSession, getErrors, getExistingSession, getFromSession, getIdParam, getIdParams, getLocale, getLoggedInUserName, getMessages, getOperation, getOrderBy, getParam, getParamUnsafe, getRequestParser, getResponsePage, getTimeZone, getUserId, hasErrors, removeFromSession, setResponsePage |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final RequestParameter SupportedOperation
This action supports :
The source of the Operation is described byActionImpl.getOperation()
.
Constructor Detail |
---|
protected ActionTemplateListAndEdit(ResponsePage aForward, ResponsePage aRedirect, RequestParser aRequestParser)
aForward
- used for Operation.List
and Operation.FetchForChange
operations, and also for failed Operation.Add
, Operation.Change
,
and Operation.Delete
operations. This is the default response.aRedirect
- used for successful Operation.Add
,
Operation.Change
, and Operation.Delete
operations.aRequestParser
- passed to the superclass constructor.Method Detail |
---|
public final ResponsePage execute() throws AppException
In order to clearly understand the operation of this method, here is the core of its implementation, with all abstract methods in italics :
if (Operation.List == getOperation() ){ doList(); } else if (Operation.FetchForChange == getOperation()){ attemptFetchForChange(); } else if (Operation.Add == getOperation()) { validateUserInput(); if ( ! hasErrors() ){ attemptAdd(); ifNoErrorsRedirectToListing(); } } else if (Operation.Change == getOperation()) { validateUserInput(); if ( ! hasErrors() ){ attemptChange(); ifNoErrorsRedirectToListing(); } } else if(Operation.Delete == getOperation()) { attemptDelete(); ifNoErrorsRedirectToListing(); } //Fresh listing WITHOUT a redirect is required if there is an error, //and for successful FetchForChange operations. if( hasErrors() || Operation.FetchForChange == getOperation() ){ doList(); }
execute
in interface Action
execute
in class ActionImpl
AppException
protected abstract void validateUserInput()
Applied to Operation.Add
and Operation.Change
. If an error occurs, then
addError must be called.
Example of a typical implementation :
protected void validateUserInput() { try { ModelFromRequest builder = new ModelFromRequest(getRequestParser()); fResto = builder.build(Resto.class, RESTO_ID, NAME, LOCATION, PRICE, COMMENT); } catch (ModelCtorException ex){ addError(ex); } }
Note that the Model Object constructed in this example (fResto) is retained as a field, for later use when applying an edit to the database. This is the recommended style.
protected abstract void doList() throws DAOException
DAOException
protected abstract void attemptAdd() throws DAOException
validateUserInput()
.
DAOException
protected abstract void attemptFetchForChange() throws DAOException
DAOException
protected abstract void attemptChange() throws DAOException
validateUserInput()
.
DAOException
protected abstract void attemptDelete() throws DAOException
DAOException
protected void addDynamicParameterToRedirectPage(String aParamName, String aParamValue)
ResponsePage
.
This method will URL-encode the name and value.
|
Version 4.10.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |