Apache Click is a simple JEE web application framework for commercial Java developers.
Apache Click is an open source project, licensed under the Apache license .
Click uses an event based programming model for processing Servlet requests and Velocity for rendering the response. (Note other template engines such as JSP and Freemarker are also supported)
This framework uses a single servlet, called ClickServlet, to act as a request dispatcher. When a request arrives ClickServlet creates a Page object to process the request and then uses the page's Velocity template to render the results.
Pages provide a simple thread safe programming environment, with a new page instance created for each servlet request.
Possibly the best way to see how Click works is to dive right in and look at some examples. (The examples are also available online at http://click.avoka.com/click-examples/ under the menu "Intro Examples".)
A Hello World example in Click would look something like this.
First we create a HelloWorld
page class:
package examples.page; import java.util.Date; import org.apache.click.Page; public HelloWorld extends Page { private Date time = new Date(); public HelloWorld() { addModel("time", time); } }
Next we have a page template hello-world.htm
,
where we can access the Page's time
variable using the
reference $time
:
<html>
<body>
<h2>Hello World</h2>
Hello world from Click at $time
</body>
</html>
Click is smart enough to figure out that the HelloWorld
page class maps to the template hello-world.htm
. We only
have to inform Click of the package of the HelloWorld
class, in this case examples.page. We do that through the
click.xml configuration
file which allows Click to map hello-world.htm
requests
to the examples.page.HelloWorld
page class.
<click-app> <pages package="examples.page"/> </click-app>
At runtime the following sequence of events occur. The ClickSerlvet
maps a GET hello-world.htm
request to our page class
example.page.HelloWorld
and creates a new instance.
The HelloWorld page creates a new private Date object,
which is added to the page's model under the name time
.
The page model is then merged with the template which substitutes
the $time
reference with the Date
object. Velocity then renders the merged template as: