The following three element data
types involves multiple selection options. The bean property should
be defined as a subclass of Collection, so that it contains all options:
- radio
- checkboxgroup
- select
When setting these bean properties, every object inside the
Collection should be an instance of the HTMLOption class, for example:
Vector options = new Vector();
options.add(new HTMLOption("1", "red", false));
options.add(new HTMLOption("2", "blue", true));
options.add(new HTMLOption("3", "green", false));
setFavoriteColor(options);
The HTMLOption class (com.ibm.commerce.tools.common.ui.HTMLOption)
is used to represent a selection option. This class has two types
of constructors: HTMLOption(String v, String t, Boolean s) and HTMLOption(String
v, String t, Boolean s, Boolean key), where v is the value, t is the
text, s is whether the option is selected, and key is whether this
option text is a resource bundle key or actual text. The default is
true).
One thing to notice is that for checkboxgroup, since a check box does
not have an HTML value, the value property in this case is used to
represent the actual check box HTML name, for example:
options = new Vector();
options.add(new HTMLOption("cert_db2", "db2", true));
options.add(new HTMLOption("cert_oracle", "oracle", false));
options.add(new HTMLOption("cert_was", "was", true));
options.add(new HTMLOption("cert_linux", "linux", false));
setCertificates(options);
In this example, four check boxes are generated in
the output HTML page, and finally the controller command will receive
four separate request parameters (ie. cert_db2, cert_oracle, cert_was
and cert_linux) each with a "true" or "false" value.