Source Viewer : WEB-INF/classes/org/apache/click/examples/control/ClientPanel.java
package org.apache.click.examples.control;
import org.apache.click.control.Form;
import org.apache.click.control.Panel;
import org.apache.click.control.Submit;
import org.apache.click.control.TextField;
import org.apache.click.extras.control.DateField;
import org.apache.click.extras.control.DoubleField;
/**
* Provides a reusable Panel to capture Client details.
*/
public class ClientPanel extends Panel {
private static final long serialVersionUID = 1L;
private Form form = new Form("form");
public ClientPanel(String name) {
super(name);
}
@Override
public void onInit() {
form.add(new TextField("name")).setRequired(true);
form.add(new DateField("dateJoined"));
form.add(new DoubleField("holdings"));
form.add(new Submit("save", this, "onSave"));
form.add(new Submit("cancel", this, "onCancel"));
add(form);
// Invoke super onInit AFTER controls have been added to Panel, otherwise
// the controls will not be reachable from the Panel and their onInit
// event won't be invoked.
super.onInit();
}
public boolean onSave() {
if (form.isValid()) {
// In real app one would store client in database
addModel("msg", "Successfully created new Client: '"
+ form.getFieldValue("name") + "'.");
}
return true;
}
public boolean onCancel() {
addModel("msg", "Cancelled.");
return true;
}
}