Actions

Back: SimpleExample Next: Customization

It's simple to add actions to your form. Here's the code for net.sourceforge.wicketwebbeans.examples.actions.ActionBeanPage:

01 package net.sourceforge.wicketwebbeans.examples.actions;
02 
03 import net.sourceforge.wicketwebbeans.containers.BeanForm;
04 import net.sourceforge.wicketwebbeans.examples.simple.TestBean;
05 import net.sourceforge.wicketwebbeans.model.BeanMetaData;
06 
07 import org.apache.wicket.ajax.AjaxRequestTarget;
08 import org.apache.wicket.markup.html.WebPage;
09 import org.apache.wicket.markup.html.form.Form;
10 
11 public class ActionBeanPage extends WebPage
12 {
13     public ActionBeanPage()
14     {
15         TestBean bean = new TestBean();
16         BeanMetaData meta = new BeanMetaData(bean.getClass(), null, this, null, false);
17         addnew BeanForm("beanForm", bean, meta) );
18     }
19 
20     public void save(AjaxRequestTarget target, Form form, TestBean bean)
21     {
22         info("Saved - thank you");
23     }
24 
25     public void cancel(AjaxRequestTarget target, Form form, TestBean bean)
26     {
27         info("Canceled - thank you");
28     }
29 
30     public void clearLastName(AjaxRequestTarget target, Form form, TestBean bean)
31     {
32         bean.setLastName("");
33     }
34 }
Java2html

Note the methods in ActionBeanPage.java: save, cancel, and clearLastName. These methods define the actions available from your Page (or whatever component the form is embedded in). By default, the action's label is derived from the method name. Every action method must have the following method signature:

    public void actionName(AjaxRequestTarget target, Form form, <BeanClassName> bean) 
    { 
        ...
    }

The target parameter normally null. The Wicket Form is always passed in "form" and the bean that the action applies to is in "bean". BeanClassName is the class name of the bean to which the action will apply. Optionally this may be "Object" if the action should apply to all beans on your page. WWB only automatically matches actions whose "bean" parameter type matches the bean in question or Object.

This configuration yields the following page:

Eclipse:/WicketWebBeans/doc/wiki/images/ActionBeanSimpleScreenshot.png

Back: SimpleExample Next: Customization