Monday, October 6, 2008

A complete Click application configuration example

Click applications are configured through the ConfigService interface.

The default ConfigService implementation is XmlConfigService which is configured through the click.xml file.

click.xml is defined by a DTD which some folk find easy to understand and follow. I however, am not one of them.

I enjoy learning from examples (not to mention it allows for easy copying and pasting) so I've put together an example of all the configuration options specified by the DTD:


<!-- A Click Application (click.xml) Example. -->
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<click-app charset="UTF-8" locale="en">

<!-- A automatically mapped Page package. Note automapping and autobinding is true by default -->
<pages package="com.mycorp.banking.page" automapping="true" autobinding="true">
<!-- A custom mapped Page -->
<page path="index.htm" classname="com.mycorp.page.Home"/>

<!-- Another mapped Page with custom headers -->
<page path="login.htm" classname="com.mycorp.page.Login">
<!-- Specify headers to cache the page for 1 hour, after which it should be reloaded -->
<header name="Pragma" value="no-cache"/>
<header name="Expires" value="1" type="Date"/>
</page>

</pages>

<!-- Another automatically mapped Page package -->
<pages package="com.mycorp.common.page"/>

<!-- Setup global headers. The headers shown below is the default used by Click -->
<headers>
<header name="Pragma" value="no-cache"/>
<header name="Cache-Control"
value="no-store, no-cache, must-revalidate, post-check=0, pre-check=0"/>
<header name="Expires" value="1" type="Date"/>
</headers>

<!-- Setup alternative Format. Default Format is net.sf.click.util.Format -->
<format classname="com.mycorp.util.Format"/>

<!-- Mode values include: [production], [profile], [development], [debug], [trace] -->
<mode value="production"/>

<!-- Set Click internal Logger to Log4J instead of the default ConsoleLogService -->
<log-service classname="net.sf.click.extras.service.Log4JLogService"/>

<!-- Set the template engine to use Freemarker instead of Velocity -->
<template-service classname="net.sf.click.extras.service.FreemarkerTemplateService"/>

<!-- Set the net.sf.click.service.CommonsFileUploadService properties: sizeMax and fileSizeMax. -->
<file-upload-service>
<!-- Set the total request maximum size to 10mb (10 x 1024 x 1024 = 10485760). The default request upload size is unlimited. -->
<property name="sizeMax" value="10485760"/>

<!-- Set the maximum individual file size to 2mb (2 x 1024 x 1024 = 2097152). The default file upload size is unlimited. -->
<property name="fileSizeMax" value="2097152"/>
</file-upload-service>
<!-- The commented section below shows how to use the classname attribute to specify -->
<!-- a custom net.sf.click.service.FileUploadService implementation. -->
<!--
<file-upload-service classname="com.mycorp.util.CustomFileUploadService">
<property name="sizeMax" value="10485760"/>
<property name="fileSizeMax" value="2097152"/>
</file-upload-service>
-->

<!-- List controls which will deploy their resources on application startup -->
<controls>
<control classname="net.sf.click.examples.control.FilterPanel"/>

<!-- A control-set which refers to a third-party xml file specifying the list of controls to deploy -->
<control-set name="mycorp-third-party-controls.xml"/>

<!-- Example mycorp-third-party-controls.xml file -->
<!--
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<click-app>
<controls>
<control classname="com.mycorp.control.MyCorpTable"/>
<control classname="com.mycorp.control.MyCorpForm"/>
</controls>
</click-app>
-->

</controls>

</click-app>