Chapter 5. Configuration

5.1. Servlet Configuration
5.1.1. Servlet Mapping
5.1.2. Load On Startup
5.1.3. Type Converter Class
5.1.4. Config Service Class
5.2. Application Configuration
5.2.1. Click App
5.2.2. Pages
5.2.2.1. Multiple Pages Packages
5.2.3. Page
5.2.3.1. Page Automapping
5.2.3.2. Automapping Excludes
5.2.3.3. Page Autobinding
5.2.3.4. Page Autobinding - Using Annotations
5.2.4. Headers
5.2.4.1. Browser Caching
5.2.5. Format
5.2.6. Mode
5.2.6.1. Page Auto Loading
5.2.6.2. Click and Velocity Logging
5.2.7. Controls
5.3. Auto Deployed Files
5.3.1. Deploying resources in a restricted environment
5.3.2. Deploying Custom Resources

This section discusses how to setup and configure an Apache Click web application.

The Click configuration files include:

  • WEB-INF/ click.xml   -   Application Configuration ( required)

  • WEB-INF/ web.xml   -   Servlet Configuration ( required)

5.1. Servlet Configuration

For a Click web application to function the ClickServlet must be configured in the web application's /WEB-INF/web.xml file. A basic web application which maps all *.htm requests to a ClickServlet is provided below.

<web-app>

  <servlet>
    <servlet-name>ClickServlet</servlet-name>
    <servlet-class>org.apache.click.ClickServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>ClickServlet</servlet-name>
    <url-pattern>*.htm</url-pattern>
  </servlet-mapping>

</web-app>

5.1.1. Servlet Mapping

By convention all Click page templates should have an .htm extension, and the ClickServlet should be mapped to process all *.htm URL requests. With this convention you have all the static HTML pages use an .html extension and they will not be processed as Click pages.

5.1.2. Load On Startup

Note you should always set load-on-startup element to be 0 so the servlet is initialized when the server is started. This will prevent any delay for the first client which uses the application.

The ClickServlet performs as much work as possible at startup to improve performance later on. The Click start up and caching strategy is configured with the Click application mode element in the "click.xml" config file, covered next.

5.1.3. Type Converter Class

The ClickServlet uses the OGNL library for type coercion when binding request parameters to bindable variables. The default type converter class used is RequestTypeConverter. To specify your own type converter configure a type-converter-class init parameter with the ClickServlet. For example:

  <servlet>
    <servlet-name>ClickServlet</servlet-name>
    <servlet-class>org.apache.click.ClickServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
    <init-param>
	    <param-name>type-converter-class</param-name>
	    <param-value>com.mycorp.util.CustomTypeConverter</param-value>
    </init-param>
  </servlet>

5.1.4. Config Service Class

Click uses a single application configuration service which is instantiated by the ClickServlet at startup. This service defines the application configuration and is used by the ClickServlet to map requests to pages amongst other things.

Once the ConfigService has been initialized it is stored in the ServletContext using the key ConfigService The default ConfigService is XmlConfigService, which configuration is discussed in detail in the next section.

To use an alternative configuration service specify a config-service-class context parameter. For example:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
   version="2.4">

 ...

     <context-param>
         <param-name>config-service-class</param-name>
          <param-value>com.mycorp.service.CustomConfigSerivce</param-value>
      </context-param>

  ...

 </web-app>