Enumerated Types

Back: NestedBeans Next: Tables

Sometimes a property represents a selection from a set of values. If the property returns a Java enum, WWB makes it really easy to present a drop-down list of choices. Let's look at net.sourceforge.wicketwebbeans.examples.enums.EnumBeanPage:

01 package net.sourceforge.wicketwebbeans.examples.enums;
02 
03 import net.sourceforge.wicketwebbeans.containers.BeanForm;
04 import net.sourceforge.wicketwebbeans.model.BeanMetaData;
05 
06 import org.apache.wicket.markup.html.WebPage;
07 
08 public class EnumBeanPage extends WebPage
09 {
10     public EnumBeanPage()
11     {
12         Customer bean = new Customer();
13         BeanMetaData meta = new BeanMetaData(bean.getClass(), null, this, null, false);
14         addnew BeanForm("beanForm", bean, meta) );
15     }
16 }
Java2html

The net.sourceforge.wicketwebbeans.examples.enums.Customer bean references a Java enum type called net.sourceforge.wicketwebbeans.examples.enums.CustomerType:

1 package net.sourceforge.wicketwebbeans.examples.enums;
2 
3 public enum CustomerType {
4     Consumer, Business, Government, International
5 }
Java2html

And here are the beanprops:

	# Enum Bean Example
	Customer {
		cols: 1;
		props: 
			firstName, lastName, 
			customerType{default: Government}; 
	}

The result looks like:

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

We specify the parameter "default" for customerType so that the the drop-down defaults to "Government". If we hadn't specified the default, the drop-down would have defaulted to null (an empty selection).

Later you'll see how to implement custom/dynamic runtime enums where the values can be derived from a database or other source.

Back: NestedBeans Next: Tables