This section discusses how to setup and configure an Apache Click web application.
The Click configuration files include:
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>
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.
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.
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>
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>