Using Apache Click with Codenvy

Create ApacheClick project off a Codenvy Factory:

Apache Click is a simple JEE web application framework for commercial Java developers. 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.

Create a Project

Log in to your Codenvy workspace and create a New WAR Project say “apacheClick”. Project file structure is shown below :


Create pom.xml File and Specify Dependencies

Specify the below dependencies in pom.xml which are prerequisite for the apacheClick implementation. Make sure these jars are included under Maven Dependencies.

  • click-2.3.0.jar
  • click.extras.2.3.0.jar




Create FormPage class

This FormPage acts as a clickServlet and creates a page object with one input field and text field. When this servlet is processed this object is passed to a HTML page (form.htm) to render the processed result.


public class FormPage extends Page  {

    private static final long serialVersionUID = 1L;

    private Form form = new Form("form");

    // Constructor ------------------------------------------------------------

    public FormPage() {

        form.add(new TextField("name", true));
        form.add(new Submit("OK"));

        form.setListener(this, "onSubmit");

    // Event Handlers ---------------------------------------------------------

     * Handle the form submit event.
    public boolean onSubmit() {
        if (form.isValid()) {
            String msg = "Your name is " + form.getFieldValue("name");
            addModel("msg", msg);
        return true;


Create click.xml and web.xml

click.xml is smart enough to figure out that the FormPage class maps to the template form.htm. We only have to inform Click of the package of the FormPage class, in this case com.codenvy.FormPage.

<click-app charset="UTF-8">
<pages package="" autobinding="annotation">
<page path="form.htm" classname="com.codenvy.FormPage"></page>
<mode value="profile"/>






Create form.htm

This html page is used to render the object processed through FormPage class.

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>MyFirstClick Welcome</title>  </head>


    #if ($msg)
      <div id="msgDiv"> $msg </div>


Build and Run the Application

Upon successful building the application and executing, it processes FormPage servlet and form object is passed to form.htm where we input a Name, upon clicking the OK button request again processed by servlet and displays the Name in the same form which has been passed as an object.