| 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.servlet.GenericServlet
javax.servlet.http.HttpServlet
net.sf.click.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>net.sf.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 "net.sf.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.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  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 pageClass,
                Throwable exception)
Creates and returns a new ErrorPage instance.  | 
protected  Page | 
createPage(Class pageClass,
           HttpServletRequest request)
Return a new Page instance for the page Class.  | 
protected  Page | 
createPage(HttpServletRequest request)
Return a new Page instance for the given request.  | 
protected  Page | 
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 | 
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 | 
handleException(HttpServletRequest request,
                HttpServletResponse response,
                boolean isPost,
                Throwable exception,
                Class 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 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 pageClass,
                HttpServletRequest request)
Return a new Page instance for the given page path, class and request.  | 
protected  void | 
processPage(Page page)
Process the given page invoking its "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 | 
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 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 CLICK_FORWARD
protected static final String FORWARD_PAGE
protected ConfigService configService
protected LogService logger
protected ognl.TypeConverter typeConverter
| Constructor Detail | 
public ClickServlet()
| Method Detail | 
public void init()
          throws ServletException
ServletException - if the application configuration service could
 not be initializedGenericServlet.init()public void destroy()
GenericServlet.destroy()
protected void doGet(HttpServletRequest request,
                     HttpServletResponse response)
              throws ServletException,
                     IOException
handleRequest(HttpServletRequest, HttpServletResponse, boolean).
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).
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)
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
protected void handleException(HttpServletRequest request,
                               HttpServletResponse response,
                               boolean isPost,
                               Throwable exception,
                               Class 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="" classname="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.
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 error
protected void processPage(Page page)
                    throws Exception
page - the Page to process
Exception - if an error occurs
protected void renderTemplate(Page page)
                       throws Exception
page - the page template to merge
Exception - if an error occurs
protected void renderJSP(Page page)
                  throws Exception
page - the page to render
Exception - if an error occurs rendering the JSPprotected Page createPage(HttpServletRequest request)
initPage(String, Class, HttpServletRequest) to create
 the Page instance and then set the properties on the page.
request - the servlet request
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 mode
protected Page initPage(String path,
                        Class 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 occurs
protected Page newPageInstance(String path,
                               Class 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.newIntance(); } 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 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
protected void setPageResponseHeaders(HttpServletResponse response,
                                      Map 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()
RequestTypeConverter instance.
protected 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 ControlRegistry createControlRegistry()
protected ErrorPage createErrorPage(Class pageClass,
                                    Throwable exception)
Context in this
 method.
pageClass - the page class with the errorexception - the error causing exception
protected ConfigService getConfigService()
protected Page createPage(String path,
                          HttpServletRequest request)
path - the Page path configured in the click.xml filerequest - the Page request
IllegalArgumentException - if the Page is not found
protected Page createPage(Class 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
  | 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||