|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.chwf.servlet.Controller
Superclass for controllers. Consult the documentation for more information about how to write controllers.
Field Summary | |
static java.lang.Object |
DEFAULT_NEW_OBJECT
Constant indicating that a controller method parameter defaults to a new object, created using Class.newInstance() . |
static java.lang.Object |
DEFAULT_NONE
Constant indicating that a controller method parameter has no default. |
static java.lang.String |
REFERER_PAGE
Constant for redirection to the referer page. |
Constructor Summary | |
Controller()
|
Method Summary | |
void |
addViewParameter(java.lang.String parameter,
java.lang.Object value)
Sets a parameter for the view redirection. |
static Controller |
getController(java.lang.Class controllerClass)
Factory method to get controller singleton. |
java.lang.Throwable |
getError()
Get the error associated with the controller's invocation, if any. |
void |
handleError(java.lang.String errorPage,
java.lang.Throwable error)
Specifies that the system redirect to the error page and pass it the specified error. |
void |
handleError(java.lang.Throwable error)
Specifies that the system redirect to the default error page and pass it the specified error. |
boolean |
hasError()
Return true if the controller invocation has an error. |
InvocationContext |
initContext()
A system method that initializes the controller's invocation context. |
void |
release()
Releases this controller from the user's session. |
void |
setView(java.lang.String url)
Set the view for the controller. |
void |
setView(java.lang.String url,
java.lang.String parameter,
java.lang.Object value)
Set the view and a single parameter value for the controller. |
void |
start()
A lifecycle method called at the beginning of each controller invocation. |
void |
stop()
A lifecycle method called at the end of each controller invocation. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.Object DEFAULT_NONE
false
.public static final java.lang.Object DEFAULT_NEW_OBJECT
Class.newInstance()
.public static final java.lang.String REFERER_PAGE
Constructor Detail |
public Controller()
Method Detail |
public static Controller getController(java.lang.Class controllerClass) throws RegistryException
controllerClass
- The controller class.RegistryException
- If the registry is not initialized.public void start() throws java.lang.Exception
java.lang.Exception
- Any exception needed for logic.public void stop() throws java.lang.Exception
A lifecycle method called at the end of each controller invocation. It
can be used to release controller resources and rollback transactions.
This method is always called, even if there were exceptions during
the controller invocation, as if this method were in a finally
block.
If there were errors, the getError()
method will return
the error object. If there were no errors, the hasError()
method returns false
. This can be used as a test to determine
whether to commit or rollback transactions.
public void stop() throws Exception { if(hasError()) { transaction.rollback(); } else { transaction.commit(); } }
java.lang.Exception
- Any exception needed for logic.public void setView(java.lang.String url)
url
- The URL to redirect to after processing is complete.public void setView(java.lang.String url, java.lang.String parameter, java.lang.Object value)
setView("/showItem.jsp", "itemId", item.getItemId());This results in the redirection URL:
/{context-path}/showItem.jsp?itemId={itemId}
url
- The URL to redirect to after processing is complete.parameter
- The parameter name.value
- The parameter value. This will be converted to a string.public void addViewParameter(java.lang.String parameter, java.lang.Object value)
addViewParameter("id", productId); addViewParameter("showSpecials", "true");
parameter
- The parameter name.value
- The parameter value. This will be converted to a string.public void handleError(java.lang.Throwable error)
error
- The error.public void handleError(java.lang.String errorPage, java.lang.Throwable error)
errorPage
- The error page.error
- The error.public java.lang.Throwable getError()
null
if there is none.public boolean hasError()
public void release() throws RegistryException
RegistryException
- If the registry is not initialized.public InvocationContext initContext()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |