|
|||||||||
| Home >> All >> org >> scopemvc >> controller >> [ servlet overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.scopemvc.controller.servlet
Class ScopeServlet

java.lang.Objectjavax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.scopemvc.controller.servlet.ScopeServlet
- All Implemented Interfaces:
- java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
- public abstract class ScopeServlet
- extends javax.servlet.http.HttpServlet
Base class for a web app's servlet dispatcher: subclass this to implement application startup and initialisation (use a static initializer). This class accepts incoming requests, collects the parameters into a mutable HashMap, parses them to create a Control and to find a ViewID to identify the View the user interacted with. The request parameters are then passed to the View to populate its Model, before the View issues the Control for the owning Controller to handle.
A configurable number of Application Controllers (and sub-Controllers and their Views and Models) are created on the first request. These are put into a pool to be shared between all future requests. For this reason, Controllers that are shared must be aware of the possible need to reset their model's state before handling a Control.
A form request is handled as follows:
Most steps in this sequence are implemented by Template Methods that can be overridden to change the default behaviour.
The issue of session state management and model scope is not resolved here.
See the various XML/XSLT and JSP servlet samples for examples of use.
- Version:
- $Revision: 1.12 $ $Date: 2002/01/26 09:46:21 $
| Nested Class Summary | |
protected class |
ScopeServlet.SharedControllerFactory
|
| Field Summary | |
static java.lang.String |
CONTROL_PARAM
The key used to identify the Control ID in the request parameters for this implementation. |
private static org.apache.commons.logging.Log |
LOG
|
protected org.scopemvc.util.ObjectPool |
sharedControllerPool
Pool of shared application Controllers for this servlet instance. |
static java.lang.String |
VALIDATION_FAILURES
The default validation error handler in handleValidationFailures(org.scopemvc.view.servlet.Page, java.util.List) 55
puts the list of ValidationFailures in the properties of the
org.scopemvc.controller.basic.ViewContext
under this key for later retrieval by a Controller. |
static java.lang.String |
VIEW_ID_PARAM
The request's key that identifies the View ID used to find the active View that a Control was sent from. |
| Fields inherited from class javax.servlet.http.HttpServlet |
|
| Fields inherited from class javax.servlet.GenericServlet |
|
| Constructor Summary | |
ScopeServlet()
|
|
| Method Summary | |
protected abstract org.scopemvc.core.Controller |
createApplicationController()
Override this to create the root application Controller. |
protected org.scopemvc.core.Control |
createControl(java.util.HashMap ioFormParameters)
Return a Control instance from request form parameters getting the Control ID from the CONTROL_PARAM form value, and setting the formParameters HashMap as the Control's parameter. |
protected abstract ServletContext |
createServletContext(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
java.util.HashMap inFormParameters)
Create a ViewContext that will be used for a request: default impl here returns a new ServletContext. |
protected void |
doGet(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
This implementation maps GET requests onto POST requests. |
protected void |
doPost(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
Default implementation uses shared application instances. |
protected org.scopemvc.view.servlet.Page |
findDefaultPage(org.scopemvc.core.Controller inRootController)
If the request ViewID doesn't match any Page then this provides a default Page: could be the start page of the application that the user gets to by invoking the servlet with no parameters. |
protected org.scopemvc.view.servlet.Page |
findPageByID(org.scopemvc.core.Controller inRootController,
java.lang.String inViewID)
Search through application's Controller hierarchy to find a Page matching the ViewID. |
protected java.lang.String |
findViewID(java.util.HashMap inParameters)
Could be overidden to provide a default ViewID if none in the parameters, but also see getFormParameters(javax.servlet.http.HttpServletRequest) 55 . |
protected java.util.HashMap |
getFormParameters(javax.servlet.http.HttpServletRequest inRequest)
Copy references to all form parameters into a mutable Map. |
protected void |
handleRequest(java.util.HashMap formParameters)
|
protected boolean |
handleValidationFailures(org.scopemvc.view.servlet.Page inPage,
java.util.List inFailures)
Called if an exception is thrown by Page.populateModel 55 . |
protected void |
initSharedControllerPool()
|
static void |
redirect(java.util.HashMap inFormParameters)
Call from a Controller instead of showing a View to force an internal redirect. |
| Methods inherited from class javax.servlet.http.HttpServlet |
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service |
| Methods inherited from class javax.servlet.GenericServlet |
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
LOG
private static final org.apache.commons.logging.Log LOG
sharedControllerPool
protected org.scopemvc.util.ObjectPool sharedControllerPool
- Pool of shared application Controllers for this servlet instance.
CONTROL_PARAM
public static java.lang.String CONTROL_PARAM
- The key used to identify the Control ID in
the request parameters for this implementation.
Initialised from the "org.scopemvc.controller.servlet.ScopeServlet.ControlParam"
value from ScopeConfig.
- See Also:
createControl(java.util.HashMap)55
VIEW_ID_PARAM
public static java.lang.String VIEW_ID_PARAM
- The request's key that identifies the View ID used to find the
active View that a Control was sent from. Initialised
from the "org.scopemvc.controller.servlet.ScopeServlet.ViewIDParam"
value of ScopeConfig.
VALIDATION_FAILURES
public static final java.lang.String VALIDATION_FAILURES
- The default validation error handler in
handleValidationFailures(org.scopemvc.view.servlet.Page, java.util.List)55 puts the list ofValidationFailures in the properties of the org.scopemvc.controller.basic.ViewContext under this key for later retrieval by a Controller.- See Also:
- Constant Field Values
| Constructor Detail |
ScopeServlet
public ScopeServlet()
| Method Detail |
doGet
protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
- This implementation maps GET requests onto POST requests.
doPost
protected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
- Default implementation uses shared application instances.
handleRequest
protected void handleRequest(java.util.HashMap formParameters)
createServletContext
protected abstract ServletContext createServletContext(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, java.util.HashMap inFormParameters)
- Create a ViewContext that will be used for a request: default
impl here returns a new ServletContext. For example
to implement your own error handling, extend the default ServletContext
to override showError, and then override this method in your
servlet subclass to create an instance of your own ServletContext.
getFormParameters
protected java.util.HashMap getFormParameters(javax.servlet.http.HttpServletRequest inRequest)
- Copy references to all form parameters into a mutable Map.
If a parameter has multiple values then the parameter value
will be a String[] else a String.
This is a useful place to insert default values for missing parameters, for example to map .../servlet/MyServlet onto some default "action" and "view" by inserting those default parameters into the returned HashMap if missing in incoming request.
createControl
protected org.scopemvc.core.Control createControl(java.util.HashMap ioFormParameters)
Return a Control instance from request form parameters getting the Control ID from the CONTROL_PARAM form value, and setting the formParameters HashMap as the Control's parameter. Also handles imagemap requests of the form
imagename.x=ControlId.Override this for an application to create a default Control when none is supplied in the request, eg for a simple home request:
http://localhost:8080/myapp/MyServlet
with no parameters to display the application's home page. But also seegetFormParameters(javax.servlet.http.HttpServletRequest)55 .
findViewID
protected java.lang.String findViewID(java.util.HashMap inParameters)
- Could be overidden to provide a default ViewID if
none in the parameters, but also see
getFormParameters(javax.servlet.http.HttpServletRequest)55 .
findPageByID
protected org.scopemvc.view.servlet.Page findPageByID(org.scopemvc.core.Controller inRootController, java.lang.String inViewID)
- Search through application's Controller hierarchy
to find a Page matching the ViewID. Return null if not found.
findDefaultPage
protected org.scopemvc.view.servlet.Page findDefaultPage(org.scopemvc.core.Controller inRootController)
- If the request ViewID doesn't match any Page
then this provides a default Page: could be the
start page of the application that the user gets to
by invoking the servlet with no parameters. Here
returns the first Page found by a depth-first
traversal of the application hierarchy.
If you manage the
getFormParameters(javax.servlet.http.HttpServletRequest)55 method to validate form parameters then this method might never be used. But if there's a single page that you want to use when an invalid ViewID is passed (eg an error page) then this is the place to do it.Don't like this. Should be allowed to redirect to an error handler on invalid ViewID? *****
handleValidationFailures
protected boolean handleValidationFailures(org.scopemvc.view.servlet.Page inPage, java.util.List inFailures)
Called if an exception is thrown by Page.populateModel 55 .
Default implementation here puts the List of
ValidationFailures into the ViewContext under theVALIDATION_FAILURES55 key for retrieval (org.scopemvc.controller.basic.ViewContext#getProperty()and handling by Controllers, ie:protected void doSomeHandler() throws ControlException { List validationFailures = (List)ViewContext.getViewContext().getProperty(ScopeServlet.VALIDATION_FAILURES); if (validationFailures != null) { // TODO: Handle the validation failures } else { // TODO: No validation failures so handle the control } }
redirect
public static void redirect(java.util.HashMap inFormParameters)
- Call from a Controller instead of showing a View to
force an internal redirect. Pass a HashMap of form
parameters for the new request.
createApplicationController
protected abstract org.scopemvc.core.Controller createApplicationController() throws java.lang.Exception
Override this to create the root application Controller. The application Controller should setup any child Controllers that it needs to handle parts of the application for it.
initSharedControllerPool
protected void initSharedControllerPool()
throws java.lang.Exception
|
|||||||||
| Home >> All >> org >> scopemvc >> controller >> [ servlet overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC