Click is an open source project, licensed using the Apache license.
Click uses the event based programming model for processing Servlet requests and Velocity for rendering the response.
This framework uses a single servlet, called ClickServlet, to act as a request dispatcher. When a request arrives ClickServlet creates a Page object to processes the request and then uses the page's Velocity template to render the results.
Page provide a simple thread safe programming environment, with a new page instance is created for each servlet request.
Possibly the best way to see how Click works is to dive right in and look an examples.
package examples.page; import java.util.Date; import net.sf.click.Page; public HelloWorld extends Page { public HelloWorld() { addModel("time", new Date()); } }Next we would have a page template hello-world.htm:
<html>
<body>
<h2>Hello World</h2>
Hello world from Click at $time
</body>
</html>
And finally we have a click.xml configuration file which tells our Click
application to map hello-world.htm
requests to our HelloWorld page class.
<click-app> <pages package="examples.page" automapping="true"/> </click-app>At runtime the ClickSerlvet maps a GET hello-world.htm request to our page class example.page.HelloWorld and creates a new instance. The HelloWorld page constructor creates a new Date object and adds it to its model as a value called time. The page model is then merged with the template which substitutes the $time parameter with the Date object. Velocity then renders the merged template which looks something like
Hello WorldHello world from Click at Wed May 28 15:52:29 EST 2005 |
public class Login extends Page { private Form form = new Form("form"); public Login() { form.add(new TextField("username", true)); form.add(new PasswordField("password", true)); form.add(new Submit("ok", " OK ", this, "onOkClicked")); form.add(new Submit("cancel", this, "onCancelClicked")); addControl(form); } public boolean onOkClicked() { if (form.isValid()) { User user = new User(); form.copyTo(user); if (getUserService().isAuthenticatedUser(user)) { getContext().setSessionAttribute("user", user); setRedirect("secure.htm"); } else { form.setError(getMessage("authentication-error")); } } return true; } public boolean onCancelClicked() { setRedirect("index.htm"); return true; } }Next we have the Login page template login.htm:
<html>
<body>
<h2>Login</h2>
$form
</body>
</html>
When the Login page is first requested the $form object will
automatically render itself as:
Login
|
Login
|