Options (Enum)
Many property is Enum type. A enum include a series of options, NUI allows define those options
in config file(or a OptionProvider implementor) and reference it in template.
Enum Property
Identify enum property by change its type into enum in class template.
Now add a enum property into Mail class:
private int priority = 2 ;
// Getter & setter needed.
Then register it in class template(samples/Mail.nui.xml) as a enum property:
<property name="priority" type="enum">
</property>
Reference Options
NUI use package-name.class-name.property-name as the default name to reference a Option Provider.
A enum property use the default name to render it's options if no name specified.
If you want to use another options, you should assign in property template file:
<property name="priority" editor="enum(options='another.options.key')">
Write a Options Config
NUI options config writed in .nop.xml("nop" = NUI OPtions).
NUI recommands place nop file in class path and use class(reference to the options) name as file name.
In this sample, we create a file "Mail.nop.xml" and place it in the same directory with Class File.
<?xml version="1.0"?>
<nui>
<options name="priority" title="Priority">
<option value="1">High</option>
<option value="2">Normal</option>
<option value="3">Low</option>
</options>
</nui>
NUI search nop file in classpath. In this sample, NUI also try to load options in follwing files:
- /samples/package.nop.xml: package level config file. Options name should be "Mail.priority".
- /samples/Mail.nop.xml: class level config file. Options name should be "priority".
- /samples/Mail.priority.nop.xml: single options config file. Options name should be empty("").
- /samples.Mail.priority.nop.xml: single options config file. Options name should be empty("").
- Base class and interfaces(include sub-interfaces).
If specified options appears in multi-files, last one will WIN.
If enum property has no title template defined,
the title of options is used as property title.
NUI will support nop file finding in Web Context in future.
Use Options in Value, Editor and Title
Just add property "priority" into property list:
<n:loop for="{'sender' , 'receiver' , 'priority', 'createDate' , 'subject'}" id="'propertyName'">
Now you can find a drop-down list in createmail.jsp.jsp, and priority value is "Normal" in showmail.jsp instead of "2".

Implements Option Factory
NUI define enum option as interface OptionEntry. This interface contains two properties: value, title
(similar with value and text of a <option> tag).
A group of options is organized in a OptionProvider interface, this interface provide method access to
option list.
Options also could be group as a OptionGroup, there has no certain interface just return by
OptionProvider.getGroups(). Method isSupportGroup() indicates whether this options support group or not.
Method getOptions(group) return options of specified group. A option group equals to a <l;optgroup> tag.
NUI use OptionFactory to manage option providers. NUI allow custom OptionFactory implementor.
A custom OptionFactry(must be a subclass of OptionFactory and implement method getProviderImpl())
should register itself into OptionFactory by method registerFactory().
Notes: To get a OptionProvider, OptionFactory iterates all registered factories in revers order,
it say later a factory registered, early be called.
And NuiOptionEntry is the first factory implementor, so it be called at the last.
Next