|
|||||||||
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.apache.click.ClickServlet
public class ClickServlet
Provides the Click application HttpServlet.
Generally developers will simply configure the ClickServlet and will not use it directly in their code. For a Click web application to function the ClickServlet must be configured in the web application's /WEB-INF/web.xml file. A simple web application which maps all *.htm requests to a ClickServlet is provided below.<web-app> <servlet> <servlet-name>click-servlet</servlet-name> <servlet-class>org.apache.click.ClickServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>click-servlet</servlet-name> <url-pattern>*.htm</url-pattern> </servlet-mapping> </web-app>By default the ClickServlet will attempt to load an application configuration file using the path: /WEB-INF/click.xml
ConfigService
instance is created by the ClickServlet at
startup. Once the ConfigService has been initialized it is stored in the
ServletContext using the key "org.apache.click.service.ConfigService".
Field Summary | |
---|---|
protected static String |
CLICK_FORWARD
The forwarded request marker attribute: "click-forward". |
protected static String |
CONFIG_SERVICE_CLASS
The click application configuration service classname init parameter name: "config-service-class". |
protected ConfigService |
configService
The click application configuration service. |
protected static String |
FORWARD_PAGE
The Page to forward to request attribute: "click-page". |
protected LogService |
logger
The application log service. |
protected ognl.MemberAccess |
memberAccess
The OGNL member access handler. |
protected ResourceService |
resourceService
The application resource service. |
protected static String |
TYPE_CONVERTER_CLASS
The custom TypeConverter classname as an init parameter name: &nbps; "type-converter-class". |
protected ognl.TypeConverter |
typeConverter
The request parameters OGNL type converter. |
Constructor Summary | |
---|---|
ClickServlet()
|
Method Summary | ||
---|---|---|
protected void |
activatePageInstance(Page page)
Provides an extension point for ClickServlet sub classes to activate stateful page which may have been deserialized. |
|
protected ActionEventDispatcher |
createActionEventDispatcher()
Creates and returns a new ActionEventDispatcher instance. |
|
protected Context |
createContext(HttpServletRequest request,
HttpServletResponse response,
boolean isPost)
Creates and returns a new Context instance for this path, class and request. |
|
protected ControlRegistry |
createControlRegistry()
Creates and returns a new ControlRegistry instance. |
|
protected ErrorPage |
createErrorPage(Class<? extends Page> pageClass,
Throwable exception)
Creates and returns a new ErrorPage instance. |
|
protected
|
createPage(Class<T> pageClass,
HttpServletRequest request)
Return a new Page instance for the page Class. |
|
protected Page |
createPage(Context context)
Return a new Page instance for the given request context. |
|
protected
|
createPage(String path,
HttpServletRequest request)
Return a new Page instance for the given path. |
|
protected PageImports |
createPageImports(Page page)
Creates and returns a new PageImports instance for the specified page. |
|
protected Map<String,Object> |
createTemplateModel(Page page)
Return a new VelocityContext for the given pages model and Context. |
|
void |
destroy()
|
|
protected void |
doGet(HttpServletRequest request,
HttpServletResponse response)
Handle HTTP GET requests. |
|
protected void |
doPost(HttpServletRequest request,
HttpServletResponse response)
Handle HTTP POST requests. |
|
protected ConfigService |
getConfigService()
Return the application configuration service instance. |
|
protected ognl.TypeConverter |
getTypeConverter()
Return the request parameters OGNL TypeConverter. |
|
protected void |
handleAjaxException(HttpServletRequest request,
HttpServletResponse response,
boolean isPost,
Throwable exception,
Class<? extends Page> pageClass)
Provides an Ajax exception handler. |
|
protected void |
handleException(HttpServletRequest request,
HttpServletResponse response,
boolean isPost,
Throwable exception,
Class<? extends Page> pageClass)
Provides the application exception handler. |
|
protected void |
handleRequest(HttpServletRequest request,
HttpServletResponse response,
boolean isPost)
Handle the given servlet request and render the results to the servlet response. |
|
void |
init()
Initialize the Click servlet and the Velocity runtime. |
|
protected Page |
initPage(String path,
Class<? extends Page> pageClass,
HttpServletRequest request)
Initialize a new page instance using newPageInstance(String, Class, HttpServletRequest) method and
setting format, headers and the forward if a JSP. |
|
protected Page |
newPageInstance(String path,
Class<? extends Page> pageClass,
HttpServletRequest request)
Return a new Page instance for the given page path, class and request. |
|
protected void |
performOnInit(Page page,
Context context)
Perform the onInit event callback for the specified page. |
|
protected void |
performOnPostOrGet(Page page,
Context context,
boolean isPost)
Perform onPost or onGet event callback for the specified page. |
|
protected boolean |
performOnProcess(Page page,
Context context,
ActionEventDispatcher eventDispatcher)
Perform onProcess event callback for the specified page, returning true if processing should continue, false otherwise. |
|
protected void |
performOnRender(Page page,
Context context)
Perform onRender event callback for the specified page. |
|
protected boolean |
performOnSecurityCheck(Page page,
Context context)
Perform the onSecurityCheck event callback for the specified page, returning true if processing should continue, false otherwise. |
|
protected ActionResult |
performPageAction(Page page,
String pageAction,
Context context)
Perform the page action for the given page and return the action result. |
|
protected void |
performRender(Page page,
Context context)
Performs rendering of the specified page. |
|
protected void |
performRender(Page page,
Context context,
ActionResult actionResult)
Performs rendering of the specified page. |
|
protected void |
processAjaxPageEvents(Page page,
Context context)
Process the given page events, invoking the "on" event callback methods and directing the response. |
|
protected boolean |
processAjaxTargetControls(Context context,
ActionEventDispatcher eventDispatcher,
ControlRegistry controlRegistry)
Process all Ajax target controls and return true if the page should continue processing, false otherwise. |
|
protected void |
processPage(Page page)
Process the given page invoking its "on" event callback methods and directing the response. |
|
protected void |
processPageEvents(Page page,
Context context)
Process the given page events, invoking the "on" event callback methods and directing the response. |
|
protected void |
processPageOnDestroy(Page page,
long startTime)
Process the given pages controls onDestroy methods, reset the pages navigation state and process the pages onDestroy method. |
|
protected void |
processPageRequestParams(Page page)
Process the page binding any request parameters to any public Page fields with the same name which are "primitive" types. |
|
protected void |
renderActionResult(ActionResult actionResult,
Page page,
Context context)
Render the given ActionResult. |
|
protected void |
renderJSP(Page page)
Render the given page as a JSP to the response. |
|
protected void |
renderTemplate(Page page)
Render the Velocity template defined by the page's path. |
|
protected void |
setPageResponseHeaders(HttpServletResponse response,
Map<String,Object> headers)
Set the HTTP headers in the servlet response. |
|
protected void |
setRequestAttributes(Page page)
Set the page model, context, format, messages and path as request attributes to support JSP rendering. |
Methods inherited from class javax.servlet.http.HttpServlet |
---|
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service |
Methods inherited from class javax.servlet.GenericServlet |
---|
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final String CONFIG_SERVICE_CLASS
protected static final String TYPE_CONVERTER_CLASS
protected static final String CLICK_FORWARD
protected static final String FORWARD_PAGE
protected ConfigService configService
protected LogService logger
protected ognl.MemberAccess memberAccess
protected ResourceService resourceService
protected ognl.TypeConverter typeConverter
Constructor Detail |
---|
public ClickServlet()
Method Detail |
---|
public void init() throws ServletException
init
in class GenericServlet
ServletException
- if the application configuration service could
not be initializedGenericServlet.init()
public void destroy()
destroy
in interface Servlet
destroy
in class GenericServlet
GenericServlet.destroy()
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
handleRequest(HttpServletRequest, HttpServletResponse, boolean)
.
doGet
in class HttpServlet
request
- the servlet requestresponse
- the servlet response
ServletException
- if click app has not been initialized
IOException
- if an I/O error occursHttpServlet.doGet(HttpServletRequest, HttpServletResponse)
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
handleRequest(HttpServletRequest, HttpServletResponse, boolean)
.
doPost
in class HttpServlet
request
- the servlet requestresponse
- the servlet response
ServletException
- if click app has not been initialized
IOException
- if an I/O error occursHttpServlet.doPost(HttpServletRequest, HttpServletResponse)
protected void handleRequest(HttpServletRequest request, HttpServletResponse response, boolean isPost) throws IOException
handleException(HttpServletRequest, HttpServletResponse, boolean, Throwable, Class)
request
- the servlet request to processresponse
- the servlet response to render the results toisPost
- determines whether the request is a POST
IOException
- if resource request could not be servedprotected void handleException(HttpServletRequest request, HttpServletResponse response, boolean isPost, Throwable exception, Class<? extends Page> pageClass)
ErrorPage
and the page template is "click/error.htm"
Applications which wish to provide their own customized error handling
must subclass ErrorPage and specify their page in the
"/WEB-INF/click.xml" application configuration file. For example:
<page path="com.mycorp.util.ErrorPage"/>If the ErrorPage throws an exception, it will be logged as an error and then be rethrown nested inside a RuntimeException. " classname="
request
- the servlet request with the associated errorresponse
- the servlet responseisPost
- boolean flag denoting the request method is "POST"exception
- the error causing exceptionpageClass
- the page class with the errorprotected void processPage(Page page) throws Exception
page
- the Page to process
Exception
- if an error occursprocessPageEvents(org.apache.click.Page, org.apache.click.Context)
protected void processPageEvents(Page page, Context context) throws Exception
page
- the Page which events to processcontext
- the request context
Exception
- if an error occursprotected boolean performOnSecurityCheck(Page page, Context context)
page
- the page to perform the security check oncontext
- the request context
protected ActionResult performPageAction(Page page, String pageAction, Context context)
page
- the page which action to performpageAction
- the name of the page actioncontext
- the request context
protected void performOnInit(Page page, Context context)
page
- the page to initializecontext
- the request contextprotected boolean performOnProcess(Page page, Context context, ActionEventDispatcher eventDispatcher)
page
- the page to processcontext
- the request contexteventDispatcher
- the action event dispatcher
protected void performOnPostOrGet(Page page, Context context, boolean isPost)
page
- the page for which the onGet or onPost is performedcontext
- the request contextisPost
- specifies whether the request is a post or a getprotected void performOnRender(Page page, Context context)
page
- page to rendercontext
- the request contextprotected void performRender(Page page, Context context) throws Exception
page
- page to rendercontext
- the request context
Exception
- if error occursprotected void performRender(Page page, Context context, ActionResult actionResult) throws Exception
page
- page to rendercontext
- the request contextactionResult
- the action result
Exception
- if error occursprotected void renderTemplate(Page page) throws Exception
page
- the page template to merge
Exception
- if an error occursprotected void renderJSP(Page page) throws Exception
page
- the page to render
Exception
- if an error occurs rendering the JSPprotected void renderActionResult(ActionResult actionResult, Page page, Context context)
actionResult
- the action result to renderpage
- the requested pagecontext
- the request contextprotected Page createPage(Context context)
initPage(String, Class, HttpServletRequest)
to create
the Page instance and then set the properties on the page.
context
- the page request context
protected void processPageOnDestroy(Page page, long startTime)
page
- the page to processstartTime
- the start time to log if greater than 0 and not in
production modeprotected Page initPage(String path, Class<? extends Page> pageClass, HttpServletRequest request)
newPageInstance(String, Class, HttpServletRequest)
method and
setting format, headers and the forward if a JSP.
This method will also automatically register any public Page controls
in the page's model. When the page is created any public visible
page Control variables will be automatically added to the page using
the method Page.addControl(Control)
method. If the controls name
is not defined it is set to the member variables name before it is added
to the page.
This feature saves you from having to manually add the controls yourself.
If you don't want the controls automatically added, simply declare them
as non public variables.
An example auto control registration is provided below. In this example
the Table control is automatically added to the model using the name
"table", and the ActionLink controls are added using the names
"editDetailsLink" and "viewDetailsLink".
public class OrderDetailsPage extends Page { public Table table = new Table(); public ActionLink editDetailsLink = new ActionLink(); publicActionLink viewDetailsLink = new ActionLink(); public OrderDetailsPage() { .. } }
path
- the page pathpageClass
- the page classrequest
- the page request
protected void processPageRequestParams(Page page) throws ognl.OgnlException
getTypeConverter()
method.
page
- the page whose fields are to be processed
ognl.OgnlException
- if an error occursprotected Page newPageInstance(String path, Class<? extends Page> pageClass, HttpServletRequest request) throws Exception
protected Page newPageInstance(String path, Class pageClass, HttpServletRequest request) throws Exception { return (Page) pageClass.newInstance(); }This method is designed to be overridden by applications providing their own page creation patterns. A typical example of this would be with Inversion of Control (IoC) frameworks such as Spring or HiveMind. For example a Spring application could override this method and use a ApplicationContext to instantiate new Page objects:
protected Page newPageInstance(String path, Class pageClass, HttpServletRequest request) throws Exception { String beanName = path.substring(0, path.indexOf(".")); if (applicationContext.containsBean(beanName)) { Page page = (Page) applicationContext.getBean(beanName); } else { page = (Page) pageClass.newInstance(); } return page; }
path
- the request page pathpageClass
- the page Class the request is mapped torequest
- the page request
Exception
- if an error occurs creating the Pageprotected void activatePageInstance(Page page)
page
- the page instance to activateprotected Map<String,Object> createTemplateModel(Page page)
Format
object for formatting
the display of objectsPageImports
objectSessionMap
adaptor for the
users HttpSession
page
- the page to create a VelocityContext for
ClickUtils.createTemplateModel(org.apache.click.Page, org.apache.click.Context)
protected void setPageResponseHeaders(HttpServletResponse response, Map<String,Object> headers)
Page.getHeaders()
.
response
- the response to set the headers inheaders
- the map of HTTP headers to set in the responseprotected void setRequestAttributes(Page page)
Format
object for
formatting the display of objectsPageImports
object
page
- the page to set the request attributes onprotected ognl.TypeConverter getTypeConverter() throws RuntimeException
RequestTypeConverter
instance.
RuntimeException
- if the TypeConverter instance could not be createdprotected Context createContext(HttpServletRequest request, HttpServletResponse response, boolean isPost)
request
- the page requestresponse
- the page responseisPost
- true if this is a post request, false otherwise
protected ActionEventDispatcher createActionEventDispatcher()
protected ControlRegistry createControlRegistry()
protected ErrorPage createErrorPage(Class<? extends Page> pageClass, Throwable exception)
Context
in this
method.
pageClass
- the page class with the errorexception
- the error causing exception
protected ConfigService getConfigService()
protected <T extends Page> T createPage(String path, HttpServletRequest request)
path
- the path which maps to a Page classrequest
- the Page request
IllegalArgumentException
- if the Page is not foundprotected <T extends Page> T createPage(Class<T> pageClass, HttpServletRequest request)
pageClass
- the class of the Page to createrequest
- the Page request
IllegalArgumentException
- if the Page Class is not configured
with a unique pathprotected PageImports createPageImports(Page page)
page
- the page to create a new PageImports instance for
protected void processAjaxPageEvents(Page page, Context context) throws Exception
page
- the page which events to processcontext
- the request context
Exception
- if an error occursprotected boolean processAjaxTargetControls(Context context, ActionEventDispatcher eventDispatcher, ControlRegistry controlRegistry)
context
- the request contexteventDispatcher
- the event dispatchercontrolRegistry
- the control registry
protected void handleAjaxException(HttpServletRequest request, HttpServletResponse response, boolean isPost, Throwable exception, Class<? extends Page> pageClass)
HTTP 500 error
which allows the JavaScript that initiated the Ajax request to handle
the error as appropriate.
If Click is running in development modes the exception stackTrace
will be rendered, in production modes an error message is
rendered.
Below is an example error response:
<div id='errorReport' class='errorReport'> The application encountered an unexpected error. </div>
request
- the servlet requestresponse
- the servlet responseisPost
- determines whether the request is a POSTexception
- the error causing exceptionpageClass
- the page class with the error
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |