Click
Click Examples

Source Viewer : WEB-INF/classes/org/apache/click/examples/page/jsp/EditCustomerPage.java

package org.apache.click.examples.page.jsp;

import org.apache.click.control.FieldSet;
import org.apache.click.control.Form;
import org.apache.click.control.Submit;
import org.apache.click.control.TextField;
import org.apache.click.examples.page.BorderPage;
import org.apache.click.extras.control.DateField;
import org.apache.click.extras.control.DoubleField;
import org.apache.click.extras.control.EmailField;

/**
 * Demo a form submit using JSP as template.
 */
public class EditCustomerPage extends BorderPage {

    private static final long serialVersionUID = 1L;

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

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

    public EditCustomerPage() {
        addControl(form);

        // Setup customers form
        FieldSet fieldSet = new FieldSet("customer");
        fieldSet.add(new TextField("name", true));
        fieldSet.add(new EmailField("email"));
        fieldSet.add(new DoubleField("holdings", true));
        fieldSet.add(new DateField("dateJoined"));
        form.add(fieldSet);
        form.add(new Submit("save", this, "onSaveClick"));
        form.add(new Submit("cancel", this, "onCancelClick"));
    }

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

    @Override
    public boolean onSecurityCheck() {
        return form.onSubmitCheck(this, EditCustomerPage.class);
    }

    public boolean onSaveClick() {
        if (form.isValid()) {
            // Perform logic
            // Optionally forward to another Page for display:
            // setForward(ViewCustomersPage.class);
        }
        return true;
    }

    public boolean onCancelClick() {
        form.clearErrors();
        form.clearValues();
        return true;
    }

    // Public Methods ---------------------------------------------------------

    /**
     * Returns the name of the border template: &nbsp; <tt>"/border-template.jsp"</tt>
     *
     * @see org.apache.click.Page#getTemplate()
     */
    @Override
    public String getTemplate() {
        return "/border-template.jsp";
    }
}