|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.servlet.GenericServlet | +--javax.servlet.http.HttpServlet | +--org.scopemvc.controller.servlet.ScopeServlet
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.
ServletContext
,
XSLScopeServlet
,
JSPScopeServlet
,
Serialized FormNested 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. |
protected 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)
puts the list of ValidationFailure s in
the properties of the 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. |
Constructor Summary | |
ScopeServlet()
Constructor for the ScopeServlet object |
Method Summary | |
protected abstract Controller |
createApplicationController()
Override this to create the root application Controller. |
protected 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 Page |
findDefaultPage(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 Page |
findPageByID(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) . |
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(Page inPage,
java.util.List inFailures)
Called if an exception is thrown by Page.populateModel . |
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, 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 |
public static final java.lang.String VALIDATION_FAILURES
handleValidationFailures(org.scopemvc.view.servlet.Page, java.util.List)
puts the list of ValidationFailure
s in
the properties of the ViewContext
under this key for later retrieval by a Controller.
public static java.lang.String CONTROL_PARAM
createControl(java.util.HashMap)
public static java.lang.String VIEW_ID_PARAM
findPageByID(org.scopemvc.core.Controller, java.lang.String)
protected ObjectPool sharedControllerPool
Constructor Detail |
public ScopeServlet()
Method Detail |
public static void redirect(java.util.HashMap inFormParameters)
inFormParameters
- TODO: Describe the Parameterprotected java.util.HashMap getFormParameters(javax.servlet.http.HttpServletRequest inRequest)
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.
inRequest
- find parameters in this request
protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
doGet
in class javax.servlet.http.HttpServlet
req
- TODO: Describe the Parameterresp
- TODO: Describe the Parameter
javax.servlet.ServletException
- TODO: Describe the Exception
java.io.IOException
- TODO: Describe the Exceptionprotected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
doPost
in class javax.servlet.http.HttpServlet
req
- TODO: Describe the Parameterresp
- TODO: Describe the Parameter
javax.servlet.ServletException
- TODO: Describe the Exception
java.io.IOException
- TODO: Describe the Exceptionprotected void handleRequest(java.util.HashMap formParameters)
formParameters
- TODO: Describe the Parameterprotected abstract ServletContext createServletContext(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, java.util.HashMap inFormParameters)
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.
req
- TODO: Describe the Parameterresp
- TODO: Describe the ParameterinFormParameters
- TODO: Describe the Parameter
protected 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/MyServletwith no parameters to display the application's home page. But also see
getFormParameters(javax.servlet.http.HttpServletRequest)
.
ioFormParameters
- request's form parameters.
protected java.lang.String findViewID(java.util.HashMap inParameters)
getFormParameters(javax.servlet.http.HttpServletRequest)
.
inParameters
- TODO: Describe the Parameter
protected Page findPageByID(Controller inRootController, java.lang.String inViewID)
inRootController
- TODO: Describe the ParameterinViewID
- TODO: Describe the Parameter
protected Page findDefaultPage(Controller inRootController)
If you manage the getFormParameters(javax.servlet.http.HttpServletRequest)
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? *****
inRootController
- TODO: Describe the Parameter
protected boolean handleValidationFailures(Page inPage, java.util.List inFailures)
Called if an exception is thrown by Page.populateModel
.
Default implementation here puts the List of ValidationFailure
s into the ViewContext under
the VALIDATION_FAILURES
key for retrieval (ViewContext.getProperty(java.lang.String)
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 } }
inPage
- TODO: Describe the ParameterinFailures
- TODO: Describe the Parameter
protected abstract 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.
java.lang.Exception
- on any failureprotected void initSharedControllerPool() throws java.lang.Exception
java.lang.Exception
- TODO: Describe the Exception
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |