| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
| "http://www.w3.org/TR/html4/loose.dtd"> | |
| <!-- | |
| Licensed to the Apache Software Foundation (ASF) under one | |
| or more contributor license agreements. See the NOTICE file | |
| distributed with this work for additional information | |
| regarding copyright ownership. The ASF licenses this file | |
| to you under the Apache License, Version 2.0 (the | |
| "License"); you may not use this file except in compliance | |
| with the License. You may obtain a copy of the License at | |
| http://www.apache.org/licenses/LICENSE-2.0 | |
| Unless required by applicable law or agreed to in writing, | |
| software distributed under the License is distributed on an | |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| KIND, either express or implied. See the License for the | |
| specific language governing permissions and limitations | |
| under the License. | |
| --> | |
| <html> | |
| <head> | |
| <!-- saved from url=(0014)about:internet --> | |
| <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> | |
| <meta name="Author" content="Malcolm Edgar"/> | |
| <meta name="description" lang="en" content="Apache Click Java web application framework"/> | |
| <meta name="keywords" lang="en" content="Apache Click, Click Framework, Java, JEE, J2EE, web application framework, open source"/> | |
| <title>Apache Click</title> | |
| <link rel="stylesheet" type="text/css" href="../help.css"/> | |
| <link rel="stylesheet" type="text/css" href="../syntax-highlighter.css"/> | |
| <style type="text/css"> | |
| .items { | |
| margin-bottom: 0.25em; | |
| } | |
| </style> | |
| <script type="text/javascript" src="../syntax-highlighter.js"></script> | |
| </head> | |
| <!--Activate syntax highlighting--> | |
| <body onload="prettyPrint();"> | |
| <h1>Configuration</h1> | |
| <p/> | |
| This section discusses how to setup and configure a Click web application and | |
| covers the following topics: | |
| <ol> | |
| <li><a href="#servlet-configuration">Servlet Configuration</a> - how to setup the ClickServlet | |
| </li> | |
| <li><a href="#application-configuration">Application Configuration</a> - how to configure the Click application | |
| descriptor | |
| </li> | |
| <li><a href="#auto-deployed-files">Auto Deployed Files</a> - automatically deployed Click files | |
| </li> | |
| </ol> | |
| <p> </p> | |
| The Click configuration files include: | |
| <table style="margin: 1em"> | |
| <tr valign="top"> | |
| <td> | |
| <img alt="Click application configuration files" src="../images/config-files.png"/> | |
| </td> | |
| <td> | |
| <ul> | |
| <li>WEB-INF/<a target='topic' href="#application-configuration">click.xml</a> | |
| - Application Configuration (<b>required</b>) | |
| </li> | |
| <li>WEB-INF/<a target='topic' href="#servlet-configuration">web.xml</a> | |
| - Servlet Configuration (<b>required</b>) | |
| </li> | |
| </ul> | |
| </td> | |
| </tr> | |
| </table> | |
| <a name="servlet-configuration" class="heading"></a><h2>1. Servlet Configuration</h2> | |
| For a Click web application to function the | |
| <a target="topic" href="click-api/org/apache/click/ClickServlet.html">ClickServlet</a> | |
| must be configured in the web application's <tt>/WEB-INF/web.xml</tt> file. | |
| A basic web application which maps all <tt>*.htm</tt> requests to a ClickServlet | |
| is provided below. | |
| <pre class="codeConfig"> | |
| <web-app> | |
| <servlet> | |
| <servlet-name><span class="blue">ClickServlet</span></servlet-name> | |
| <servlet-class><span class="red">org.apache.click.ClickServlet</span></servlet-class> | |
| <load-on-startup><span class="red">0</span></load-on-startup> | |
| </servlet> | |
| <servlet-mapping> | |
| <servlet-name><span class="blue">ClickServlet</span></servlet-name> | |
| <url-pattern><span class="red">*.htm</span></url-pattern> | |
| </servlet-mapping> | |
| </web-app> | |
| </pre> | |
| <h3>1.1 Servlet Mapping</h3> | |
| By convention all Click page templates should have a .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 a .html extension | |
| and they will not be processed as Click pages. | |
| <h3>1.2 Load On Startup</h3> | |
| Note you should always set <tt>load-on-startup</tt> 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. | |
| <p/> | |
| The <tt>ClickServlet</tt> 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 "<tt>click.xml</tt>" | |
| config file, covered next. | |
| <a name="application-configuration" class="heading"></a><h2>2. Application Configuration</h2> | |
| The heart of a Click application is the <tt>click.xml</tt> configuration file. | |
| This file specifies the application pages, headers, the format object and the | |
| applications mode. | |
| <p/> | |
| By default the ClickServlet will attempt to load the application | |
| configuration file using the path: <tt>/WEB-INF/click.xml</tt> | |
| <p/> | |
| If this file is not found under the <tt>WEB-INF</tt> directory, then | |
| ClickServlet will attempt to load it from the classpath as <tt>/click.xml</tt>. | |
| <p/> | |
| See <a target='topic' href="click-dtd.html">Click DTD</a> for the click-app XML definition. | |
| <p/> | |
| A complete Click configuration example is available <a target='topic' href="click-dtd-example.html">here</a> | |
| which can be used as a quick reference when configuring Click. | |
| <p/> | |
| A basic Click app config file is provided below: | |
| <pre class="prettyprint"> | |
| <click-app> | |
| <pages package="com.mycorp.page"/> | |
| <mode value="profile"/> | |
| </click-app> | |
| </pre> | |
| <p/> | |
| An example of an advanced config file is: | |
| <pre class="prettyprint"> | |
| <click-app charset="UTF-8" locale="de"> | |
| <pages package="com.mycorp.banking.page"> | |
| <page path="index.htm" classname="Home"/> | |
| </pages> | |
| <pages package="com.mycorp.common.page"/> | |
| <format classname="com.mycorp.util.Format"/> | |
| <mode value="profile"/> | |
| <log-service classname="org.apache.click.extras.service.Log4JLogService"/> | |
| </click-app> | |
| </pre> | |
| The rest of this chapter cover Click configuration in detail. | |
| <a name="application-click-app" class="heading"></a><h3>2.1 Click App</h3> | |
| The root <span class="red">click-app</span> element defines two application | |
| localization attributes <span class="blue">charset</span> and | |
| <span class="blue">locale</span>. | |
| <pre class="codeDtd"> | |
| <!ELEMENT <span class="red">click-app</span> (pages*, headers?, format?, mode?, controls?, | |
| file-upload-service?, log-service?, template-service?)> | |
| <!ATTLIST click-app <span class="blue">charset</span> CDATA #IMPLIED> | |
| <!ATTLIST click-app <span class="blue">locale</span> CDATA #IMPLIED> | |
| </pre> | |
| The <span class="blue">charset</span> attribute defines the character encoding | |
| set for: | |
| <ul style="margin-top:0.5em"> | |
| <li class="items">Velocity templates</li> | |
| <li class="items">HttpServletRequest character encoding</li> | |
| <li class="items">Page Content-Type charset, see Page | |
| <a href="click-api/org/apache/click/Page.html#getContentType()">getContentType()</a> | |
| </li> | |
| </ul> | |
| The <span class="blue">locale</span> attribute defines the default application | |
| Locale. If this value is defined it will override Locale returned by the request. | |
| Please see the Context | |
| <a href="click-api/org/apache/click/Context.html#getLocale()">getLocale()</a> | |
| for details. | |
| <p/> | |
| For example the folliwing configuration sets the application character set to | |
| UTF-8 and the default Locale as German (de): | |
| <pre class="codeConfig"> | |
| <click-app <span class="blue">charset</span>="<span class="red">UTF-8</span>" <span class="blue">locale</span>="<span class="red">de</span>"> | |
| .. | |
| </click-app> | |
| </pre> | |
| <a name="application-pages" class="heading"></a><h3>2.2 Pages</h3> | |
| The first child element of the click-app is the mandatory <tt>pages</tt> element | |
| which defines the list of Click pages. | |
| <pre class="codeDtd"> | |
| <!ELEMENT <span class="blue">pages</span> (<span class="red">page</span>*)> | |
| <!ATTLIST pages <span class="blue">package</span> CDATA #IMPLIED> | |
| <!ATTLIST pages <span class="blue">automapping</span> (true|false) "true"> | |
| <!ATTLIST pages <span class="blue">autobinding</span> (true|false) "true"> | |
| </pre> | |
| The pages element can specify a default <span class="blue">package</span> | |
| name which is prepended to the classname of any pages defined. | |
| <p/> | |
| The pages element also defines the <span class="blue">automapping</span> attribute | |
| which is discussed in the | |
| <a href="#application-automapping">Page Automapping</a> topic. | |
| <a name="application-multi-packages" class="heading"></a><h4>2.2.1 Multiple Pages Packages</h4> | |
| Click can support multiple pages elements to enable the automapping of multiple | |
| packages. | |
| <pre class="prettyprint"> | |
| <click-app> | |
| <pages package="com.mycorp.banking.page"/> | |
| <pages package="com.mycorp.common.page"/> | |
| </click-app> | |
| </pre> | |
| With multiple pages elements, pages are loaded in the | |
| order of the page elements, with manual page elements being loaded before | |
| automapped pages. Once a page template has been mapped to a Page class it will | |
| not be replaced by a subsequent potential match. So pages elements at the top | |
| take priority over lower pages elements. | |
| <a name="application-page" class="heading"></a><h3>2.3 Page</h3> | |
| The <span class="red">page</span> element defines the Click application pages. | |
| <pre class="codeDtd"> | |
| <!ELEMENT <span class="red">page</span> (<span class="blue">header</span>*)> | |
| <!ATTLIST page <span class="blue">path</span> CDATA #REQUIRED> | |
| <!ATTLIST page <span class="blue">classname</span> CDATA #REQUIRED> | |
| </pre> | |
| Each page <span class="blue">path</span> must be unique, as the Click application maps HTTP requests to the page paths. | |
| <p/> | |
| The Click application will create a new Page instance for the given request using | |
| the configured page <span class="blue">classname</span>. All pages must subclass | |
| <a target="topic" href="click-api/org/apache/click/Page.html">Page</a> | |
| and provide a public no arguments constructor, so they can be instantiated. | |
| <p/> | |
| Pages can also define <span class="blue">header</span> values which are discussed | |
| in the next topic. | |
| <p/> | |
| When the Click application starts up it will check all the page definitions. If there | |
| is a critical configuration error the ClickSerlvet will log an <tt>ERROR</tt> message and throw an | |
| <a class="external" target="_blank" href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/UnavailableException.html">UnavailableException</a>. | |
| If this occurs the click application will be permanently unavailable until the error is fixed | |
| and the web app is restarted. | |
| <a name="application-automapping" class="heading"></a><h4>2.3.1 Page Automapping</h4> | |
| Page automapping will automatically configure application pages using a | |
| simple set of rules. This enables you to greatly streamline your configuration file | |
| as you only need to define pages which don't fit the automapping rules. | |
| <p/> | |
| Automapping will attempt to associate each page template (*.htm) and JSP file in the web | |
| application (excluding those under the WEB-INF and click directories) to a Page class. | |
| Automapped pages are loaded after the manually defined pages are loaded, and | |
| manually defined pages takes preference. When automapping is enabled the Click | |
| application will log the page mappings when in debug or trace mode. | |
| <p/> | |
| For example given a page path to class mapping: | |
| <pre class="codeConfig" style="background-color: white;"> | |
| <span class="navy">index.htm</span> => <span class="maroon">com.mycorp.page.Home</span> | |
| <span class="navy">search.htm</span> => <span class="maroon">com.mycorp.page.Search</span> | |
| <span class="navy">contacts/contacts.htm</span> => <span class="maroon">com.mycorp.page.contacts.Contacts</span> | |
| <span class="navy">security/login.htm</span> => <span class="maroon">com.mycorp.page.security.Login</span> | |
| <span class="navy">security/logout.htm</span> => <span class="maroon">com.mycorp.page.security.Logout</span> | |
| <span class="navy">security/change-password.htm</span> => <span class="maroon">com.mycorp.page.security.ChangePassword</span> | |
| </pre> | |
| This could be configured manually by setting the <span class="red">automapping</span> attribute to "false" | |
| and using the package prefix, for example: | |
| <pre class="codeConfig"> | |
| <click-app> | |
| <pages package="<span class="maroon">com.mycorp.page</span>" <span class="red">automapping</span>="<span class="blue">false</span>"> | |
| <page path="<span class="navy">index.htm</span>" classname="<span class="maroon">Home</span>"/> | |
| <page path="<span class="navy">search.htm</span>" classname="<span class="maroon">Search</span>"/> | |
| <page path="<span class="navy">contacts/contacts.htm</span>" classname="<span class="maroon">contacts.Contacts</span>"/> | |
| <page path="<span class="navy">security/login.htm</span>" classname="<span class="maroon">security.Login</span>"/> | |
| <page path="<span class="navy">security/logout.htm</span>" classname="<span class="maroon">security.Logout</span>"/> | |
| <page path="<span class="navy">security/change-password.htm</span>" classname="<span class="maroon">security.ChangePassword</span>"/> | |
| </pages> | |
| </click-app> | |
| </pre> | |
| Using automapping you only need to define the Home page which doesn't automatically | |
| map to index.html. | |
| <pre class="codeConfig"> | |
| <click-app> | |
| <pages package="<span class="maroon">com.mycorp.page</span>" <span class="red">automapping</span>="<span class="blue">true</span>"> | |
| <page path="<span class="navy">index.htm</span>" classname="<span class="maroon">Home</span>"/> | |
| </pages> | |
| </click-app> | |
| </pre> | |
| Note <span class="red">automapping</span> is true by default, so it could be omitted | |
| from the configuration file. | |
| <p/> | |
| The page template name to classname convention is: | |
| <pre class="codeConfig" style="background-color: white;"> | |
| change-password.htm => ChangePassword | |
| change_password.htm => ChangePassword | |
| changePassword.htm => ChangePassword | |
| ChangePassword.htm => ChangePassword | |
| </pre> | |
| When automapping pages, if a class cannot be found Click will attempt to add the | |
| 'Page' suffix to the classname if not already present and map this. | |
| For example: | |
| <pre class="codeConfig" style="background-color: white;"> | |
| customer.htm => CustomerPage | |
| change-password.htm => ChangePasswordPage | |
| </pre> | |
| <a name="application-excludes" class="heading"></a><h4>2.3.2 Automapping Excludes</h4> | |
| With Page automapping there can be resources where you don't want automapping | |
| applied. For example when using a JavaScript library with lots of | |
| <tt>.htm</tt> files, you don't want automapping to try and find Page class for | |
| each of these files. | |
| <p/> | |
| In these situations you can use the pages <tt>excludes</tt> element. | |
| <pre class="codeDtd"> | |
| <!ELEMENT <span class="red">excludes</span> (#PCDATA)> | |
| <!ATTLIST excludes <span class="blue">pattern</span> CDATA #REQUIRED> | |
| </pre> | |
| For example if our application uses the TinyMCE JavaScript library we could | |
| configure our pages automapping to exclude all <tt>.htm</tt> files under the | |
| <tt>/tiny_mce</tt> directory. | |
| <pre class="codeConfig"> | |
| <click-app> | |
| <pages package="com.mycorp.page"> | |
| <<span class="blue">excludes</span> pattern="<span class="red">/tiny_mce/*</span>"/> | |
| </pages> | |
| </click-app> | |
| </pre> | |
| The excludes pattern can specify multiple directories or files using a comma | |
| separated notation. For example: | |
| <pre class="codeConfig"> | |
| <click-app> | |
| <pages package="com.mycorp.page"> | |
| <<span class="blue">excludes</span> pattern="<span class="red">/dhtml/*, /tiny_mce/*, banner.htm, about.htm</span>"/> | |
| </pages> | |
| </click-app> | |
| </pre> | |
| HTM files excluded from Page automapping are handled by an internal Page class | |
| with caching headers enabled. | |
| <a name="application-autobinding" class="heading"></a><h4>2.3.3 Page Autobinding</h4> | |
| By default all pages have autobinding enabled. With autobinding enabled the | |
| ClickServlet will automatically: | |
| <ul> | |
| <li class="items">add any public controls to the page, after the page constructor has been invoked</li> | |
| <li class="items">if the public control's name is not defined, its name will be set to the the value its field name</li> | |
| <li class="items">bind any request parameters to public page fields, after page constructor has been invoked. | |
| See <a href="click-api/org/apache/click/ClickServlet.html#processPageRequestParams(org.apache.click.Page)">ClickServlet.processPageRequestParams(Page)</a> | |
| for more details | |
| </li> | |
| <li class="items">add any public page fields to the page model, before rendering</li> | |
| </ul> | |
| For example: | |
| <pre class="prettyprint"> | |
| public class EmployeePage extends Page { | |
| public Form employeeForm = new Form(); | |
| public Table myTable = new Table(); | |
| } </pre> | |
| In the example above the <span class="blue">employeeForm</span> and <span class="blue">myTable</span> | |
| controls were not added to the page. Also note that Form and Table does not have their names defined. | |
| <p/> | |
| When autobinding is enabled, ClickServlet will create a new Page and add the public | |
| controls to the page. In the example above the <span class="blue">employeeForm</span> and | |
| <span class="blue">myTable</span> will be added to the page, as if you had invoked, | |
| <em>addControl(employeeForm)</em> and <em>addControl(myTable)</em>. | |
| <p/> | |
| The control's names were not defined so ClickServlet will set their names to the value | |
| of their field/variable name. In this case the Form name will be set to <span class="blue">employeeForm</span> | |
| while the Table name will set to <span class="blue">myTable</span>. | |
| <p/> | |
| The above example is thus a shorthand way of writing the following: | |
| <pre class="prettyprint"> | |
| public class EmployeePage extends Page { | |
| private Form employeeForm = new Form(); | |
| private Table myTable = new Table(); | |
| public void onInit() { | |
| employeeForm.setName("employeeForm"); | |
| addControl(employeeForm); | |
| myTable.setName("myTable"); | |
| addControl(myTable); | |
| } | |
| } </pre> | |
| You can turn this behaviour off by setting the autobinding attribute to false, for example: | |
| <pre class="codeConfig"> | |
| <click-app> | |
| <pages package="com.mycorp.page" <span class="blue">autobinding</span>="<span class="red">false</span>"/> | |
| </click-app> | |
| </pre> | |
| <a name="application-headers" class="heading"></a><h3>2.4 Headers</h3> | |
| The optional <tt>headers</tt> element defines a list of <tt>header</tt> elements | |
| which are applied to all pages. | |
| <pre class="codeDtd"> | |
| <!ELEMENT <span class="blue">headers</span> (<span class="red">header</span>*)> | |
| </pre> | |
| The <tt><span class="red">header</span></tt> element defines header name and value | |
| pairs which are applied to the | |
| <a class="external" target="_blank" href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpServletResponse.html">HttpServletResponse</a>. | |
| <pre class="codeDtd"> | |
| <!ELEMENT <span class="red">header</span> (#PCDATA)> | |
| <!ATTLIST header <span class="blue">name</span> CDATA #REQUIRED> | |
| <!ATTLIST header <span class="blue">value</span> CDATA #REQUIRED> | |
| <!ATTLIST header <span class="blue">type</span> (String|Integer|Date) "String"> | |
| </pre> | |
| Page headers are set after the Page has been constructed and before <tt>onInit()</tt> is called. | |
| Pages can then modify their | |
| <a target="topic" href="click-api/org/apache/click/Page.html#headers">headers</a> property using | |
| the <a href="click-api/org/apache/click/Page.html#setHeader(java.lang.String, java.lang.Object)">setHeader()</a> | |
| method. | |
| <h4>2.4.1 Browser Caching</h4> | |
| Headers are typically used to switch off browser caching. By default Click will | |
| use the following no caching header values if you don't define a <tt>headers</tt> | |
| element in your application: | |
| <pre class="codeConfig"> | |
| <click-app> | |
| <pages> | |
| .. | |
| </pages> | |
| <headers> | |
| <header name="<span class="blue">Pragma</span>" value="<span class="blue">no-cache</span>"/> | |
| <header name="<span class="blue">Cache-Control</span>" | |
| value="<span class="blue">no-store, no-cache, must-revalidate, post-check=0, pre-check=0</span>"/> | |
| <header name="<span class="blue">Expires</span>" value="<span class="blue">1</span>" type="<span class="blue">Date</span>"/> | |
| </headers> | |
| </click-app> | |
| </pre> | |
| Alternatively you can define your headers individually in pages or for all application | |
| pages by setting header values. For example to switch off | |
| caching in the login page, note the value for a Date type should be a long number value: | |
| <pre class="codeConfig"> | |
| <page path="<span class="blue">login.htm</span>" classname="<span class="blue">com.mycorp.page.Login</span>"> | |
| <header name="<span class="blue">Pragma</span>" value="<span class="blue">no-cache</span>"/> | |
| <header name="<span class="blue">Expires</span>" value="<span class="blue">1</span>" type="<span class="blue">Date</span>"/> | |
| </page> | |
| </pre> | |
| If you wanted to enable caching for a particular page you could set the following page cache control header. This will mark the page | |
| as cachable for a period of 1 hour after which it should be reloaded. | |
| <pre class="codeConfig"> | |
| <page path="<span class="blue">home.htm</span>" classname="<span class="blue">com.mycorp.page.Home</span>"> | |
| <header name="<span class="blue">Cache-Control</span>" value="<span class="blue">max-age=3600, public, must-revalidate</span>"/> | |
| </page> | |
| </pre> | |
| To apply header values globally define header values in the headers element. For example: | |
| <pre class="codeConfig"> | |
| <click-app> | |
| <pages> | |
| .. | |
| </pages> | |
| <headers> | |
| <header name="<span class="blue">Pragma</span>" value="<span class="blue">no-cache</span>"/> | |
| <header name="<span class="blue">Cache-Control</span>" | |
| value="<span class="blue">no-store, no-cache, must-revalidate, post-check=0, pre-check=0</span>"/> | |
| <header name="<span class="blue">Expires</span>" value="<span class="blue">1</span>" type="<span class="blue">Date</span>"/> | |
| </headers> | |
| </click-app> | |
| </pre> | |
| <a name="application-format" class="heading"></a><h3>2.5 Format</h3> | |
| The optional <tt>format</tt> element defines the Format object classname which | |
| is applied to all pages. | |
| <pre class="codeDtd"> | |
| <!ELEMENT <span class="blue">format</span> (#PCDATA)> | |
| <ATTLIST format classname CDATA #FIXED "org.apache.click.util.Format"> | |
| </pre> | |
| By default all Click pages are configured with a | |
| <a target="topic" href="click-api/org/apache/click/util/Format.html">org.apache.click.util.Format</a> | |
| object. The format object is made available in the Velocity page templates using the name | |
| <tt>$<span class="blue">format</span></tt>. | |
| <p/> | |
| To specify a custom format class configure a <tt>format</tt> element in the click-app | |
| descriptor. For example: | |
| <pre class="codeConfig"> | |
| <click-app> | |
| .. | |
| <<span class="blue">format</span> classname="<span class="red">com.mycorp.util.CustomFormat</span>"/> | |
| </click-app> | |
| </pre> | |
| <a name="application-mode" class="heading"></a><h3>2.6 Mode</h3> | |
| The optional <tt>mode</tt> element defines the application logging and caching mode. | |
| <pre class="codeDtd"> | |
| <!ELEMENT mode (#PCDATA)> | |
| <ATTLIST mode value (<span class="blue">production</span>|<span class="blue">profile</span>|<span class="blue">development</span>|<span class="blue">debug</span>|<span class="blue">trace</span>) "development"> | |
| </pre> | |
| By default Click applications run in <tt>development</tt> mode, which switches off page | |
| template caching, and the logging level is set to <tt>INFO</tt>. | |
| <p/> | |
| To change the default application mode configure a mode element in the click-app | |
| descriptor. For example to specify <tt>production</tt> mode you would add the | |
| following mode element: | |
| <pre class="codeConfig"> | |
| <click-app> | |
| .. | |
| <<span class="blue">mode</span> value="<span class="red">production</span>"> | |
| </click-app> | |
| </pre> | |
| The application mode configuration can be overridden by setting the system | |
| property <tt>"click.mode"</tt>. This can be use in the scenario of debugging | |
| a problem on a production system, where you change the mode to <tt>trace</tt> | |
| by setting the following system property and restarting the application. | |
| <pre class="codeConfig"> | |
| -Dclick.mode=trace | |
| </pre> | |
| The Click Application modes and their settings for Page auto loading, | |
| template caching and logging levels are: | |
| <p> | |
| <table style="border: 1px solid black;" cellspacing="0" cellpadding="6"> | |
| <tr style="background-color: navy; color: white;"> | |
| <th align="center">Application mode</th> | |
| <th align="center">Page auto loading</th> | |
| <th align="center">Template caching</th> | |
| <th align="center">Click logging level</th> | |
| <th align="center">Velocity logging level</th> | |
| </tr> | |
| <tr> | |
| <td align="center"><tt><span class="blue">production</span></tt></td> | |
| <td align="center">No</td> | |
| <td align="center">Yes</td> | |
| <td align="center">WARN</td> | |
| <td align="center">ERROR</td> | |
| </tr> | |
| <tr> | |
| <td align="center"><tt><span class="blue">profile</span></tt></td> | |
| <td align="center">No</td> | |
| <td align="center">Yes</td> | |
| <td align="center">INFO</td> | |
| <td align="center">ERROR</td> | |
| </tr> | |
| <tr> | |
| <td align="center"><tt><span class="blue">development</span></tt></td> | |
| <td align="center">Yes</td> | |
| <td align="center">No</td> | |
| <td align="center">INFO</td> | |
| <td align="center">ERROR</td> | |
| </tr> | |
| <tr> | |
| <td align="center"><tt><span class="blue">debug</span></tt></td> | |
| <td align="center">Yes</td> | |
| <td align="center">No</td> | |
| <td align="center">DEBUG</td> | |
| <td align="center">ERROR</td> | |
| </tr> | |
| <tr> | |
| <td align="center"><tt><span class="blue">trace</span></tt></td> | |
| <td align="center">Yes</td> | |
| <td align="center">No</td> | |
| <td align="center">TRACE</td> | |
| <td align="center">WARN</td> | |
| </tr> | |
| </table> | |
| <a name="page-auto-loading" class="heading"></a><h4>2.6.1 Page Auto Loading</h4> | |
| When Page Auto Loading is enabled any new page templates and classes will | |
| be automatically loaded at runtime. These pages are loaded using the | |
| <a href="#application-automapping">Page Automapping</a> rules. | |
| <p/> | |
| Page auto loading is a very handy feature for rapid development | |
| as you do not have to restart you application server to pick up new pages. | |
| <a name="click-logging" class="heading"></a><h4>2.6.2 Click and Velocity Logging</h4> | |
| The Click and Velocity runtimes use | |
| <a target="topic" href="click-api/org/apache/click/service/LogService.html">LogService</a> | |
| for logging messages. The default LogService implementation is | |
| <a target="topic" href="click-api/org/apache/click/service/ConsoleLogService.html">ConsoleLogService</a> | |
| which will send messages to the console [System.out]. | |
| For example the following logging output is for a HomePage request when the application | |
| mode is <tt>trace</tt>: | |
| <pre class="codeConfig" style="padding:1em;background-color:#f0f0f0;"> | |
| [Click] [debug] GET http://localhost:8080/quickstart/home.htm | |
| [Click] [trace] invoked: HomePage.<<init>> | |
| [Click] [trace] invoked: HomePage.onSecurityCheck() : true | |
| [Click] [trace] invoked: HomePage.onInit() | |
| [Click] [trace] invoked: HomePage.onGet() | |
| [Click] [trace] invoked: HomePage.onRender() | |
| [Click] [info ] renderTemplate: /home.htm - 6 ms | |
| [Click] [trace] invoked: HomePage.onDestroy() | |
| [Click] [info ] handleRequest: /home.htm - 24 ms </pre> | |
| Any unhandled <tt>Throwable</tt> errors are logged by the ClickServlet. | |
| <p/> | |
| Note that Click Extras also provide log adaptors for <a target="topic" href="extras-api/org/apache/click/extras/service/Log4JLogService.html">Log4J</a> | |
| and the <a target="topic" href="extras-api/org/apache/click/extras/service/JdkLogService.html">JDK Logging API</a>. | |
| <p/> | |
| When an application is not in <tt>production</tt> mode the error page displays | |
| detailed debugging information. When the application mode is <tt>production</tt> | |
| no debug information is displayed to prevent sensitive information being revealed. | |
| This behaviour can be changed by modifying the deployed | |
| <span class="blue"><tt>click/error.htm</tt></span> page template. | |
| <a name="application-controls" class="heading"></a><h3>2.7 Controls</h3> | |
| The optional <tt>controls</tt> element defines a list of <tt>control</tt> elements | |
| which will be deployed on application startup. | |
| <pre class="codeDtd"> | |
| <!ELEMENT <span class="blue">controls</span> (<span class="red">control</span>*)> | |
| </pre> | |
| The <tt><span class="red">control</span></tt> registers | |
| <a href="click-api/org/apache/click/Control.html">Control</a> | |
| classes which | |
| will have their <a href="click-api/org/apache/click/Control.html#onDeploy(javax.servlet.ServletContext)">onDeploy()</a> | |
| method invoked when the click application starts. | |
| <pre class="codeDtd"> | |
| <!ELEMENT <span class="red">control</span> (#PCDATA)> | |
| <!ATTLIST control <span class="blue">classname</span> CDATA #REQUIRED> | |
| </pre> | |
| For example to have a <tt>CustomField</tt> control deploy its resources on | |
| application startup, you would add the following elements to your | |
| <tt>click.xml</tt> file: | |
| <pre class="codeConfig"> | |
| <click-app> | |
| .. | |
| <controls> | |
| <<span class="blue">control</span> classname=<span class="red">"com.mycorp.control.CustomField"</span>/> | |
| </controls> | |
| </click-app> </pre> | |
| <a name="auto-deployed-files" class="heading"></a><h2>3. Auto Deployed Files</h2> | |
| To make pre-configured resources (templates, stylesheets, etc.) available to web applications, | |
| Click automatically deploys configured classpath resources to the <tt class="blue">/click</tt> | |
| directory at startup (if not already present). | |
| <p/> | |
| You can modify these support files and Click will <b>not</b> overwrite them. These files include: | |
| <ul> | |
| <li>click/error.htm - the Page <a href="pages.html#page-error-handling">Error Handling</a> template</li> | |
| <li>click/control.css - the Controls cascading stylesheet</li> | |
| <li>click/control.js - the Controls JavaScript library</li> | |
| <li>click/not-found.htm - the <a href="pages.html#page-not-found">Page Not Found</a> template</li> | |
| </ul> | |
| <p/> | |
| For example to customize the control styles you can place a customized copy | |
| (or even a brand new version) of <tt>control.css</tt> under the <tt>/click</tt> | |
| folder in your web project: | |
| <pre> | |
| /webapp/click/control.css | |
| </pre> | |
| When Click starts up it will <tt>not</tt> override your copy of <tt>control.css</tt> | |
| with its own default version. | |
| <p/> | |
| Different controls might deploy different stylesheet, javascript or image files, however | |
| the above principle still applies. By placing a customized copy of the stylesheet, | |
| javascript or image under the <tt>/click</tt> folder, you will override the default resource. | |
| <p/> | |
| Be aware that some of the more complex controls (checklist, colorpicker, tree), | |
| deploys resources to subfolders under <tt>/click</tt>, for example <tt>/click/checklist/*</tt>. | |
| <p/> | |
| A control's Javadoc will normally indicate what resources are deployed for that control. | |
| <p/> | |
| It is generally easier to work with unpacked WARs and most servlet containers | |
| do just that. However some contains such as WebLogic (at least version 10) does not. | |
| To enable WebLogic to unpack the WAR go to the <em>Admin Console > server node > Web Applications</em> | |
| tab and check the <em>Archived Real Path Enabled</em> parameter. | |
| <p/> | |
| If Click cannot deploy resources because of restricted file system permissions, | |
| warning messages will be logged. | |
| <p/> | |
| If your application server does not unpack the WAR/EAR or has restricted permissions, | |
| you will need to package up these auto deployed files in your web applications WAR file. | |
| To do this you should run you application on a development machine without these restrictions | |
| and then package up the deployed files into the WAR/EAR before deployment. | |
| <a name="deploying-custom-resources" class="heading"></a><h3>3.1 Deploying Custom Resources</h3> | |
| <p/> | |
| Click supports two ways of deploying pre-configured resources (templates, | |
| stylesheets, JavaScript etc.) from a Jar to a web applications. | |
| <ol> | |
| <li> | |
| Through a Control's <a href="click-api/org/apache/click/Control.html#onDeploy(javax.servlet.ServletContext)">onDeploy()</a> | |
| event handler. See the <a href="#application-controls">Controls</a> section above. | |
| </li> | |
| <li> | |
| By packaging the resources (stylesheets, JavaScript, Images etc.) into a special folder called <em>'META-INF/web'</em>. | |
| </li> | |
| </ol> | |
| As option #1 was already discussed above in section <a href="#application-controls">2.7 Controls</a>, | |
| lets look at option #2. | |
| <p/> | |
| When Click starts up, it scans each Jar in the classpath for specially marked | |
| entries starting with 'META-INF/web/'. (Please note that even though Click will | |
| scan the entire classpath it is strongly recommended to host your Jar files inside | |
| your WAR lib folder e.g. WEB-INF/lib. Sharing Jars on the classpath can lead to | |
| class loading issues.) | |
| <p/> | |
| Click will then copy all files found under 'META-INF/web/' to the web application | |
| folder. | |
| <p/> | |
| For example, given a Jar file with the following entries: | |
| <ul> | |
| <li> | |
| META-INF/web/mycorp/edit_customer.js | |
| </li> | |
| <li> | |
| META-INF/web/mycorp/edit_customer.css | |
| </li> | |
| <li> | |
| mycorp/pages/EditCustomerPage.class | |
| </li> | |
| </ul> | |
| Click will copy the files <em>'/mycorp/edit_customer.js'</em> and <em>'/mycorp/edit_customer.css'</em> | |
| to the web application folder. | |
| <p/> | |
| Thus if the web application is called 'webapp', the files will be deployed as | |
| <em>'webapp/mycorp/edit_customer.js'</em> and <em>'webapp/mycorp/edit_customer.css'</em>. | |
| <p/> | |
| Option #2 is especially useful when you need to deploy a large number of | |
| resources from a Jar. Note, only Jars placed under the <em>'WEB-INF/lib'</em> folder will | |
| be deployed. | |
| </body> | |
| </html> |