org.apache.click.control
Class Option

java.lang.Object
  extended by org.apache.click.control.Option
All Implemented Interfaces:
Serializable

public class Option
extends Object
implements Serializable

Provides a select Option element:   <option></option>.

The Option class uses an immutable design so Option instances can be shared by multiple Pages in the multi-threaded Servlet environment. This enables Option instances to be cached as static variables.

Option Example

The example below caches Option and OptionGroup instances in a static List to provide a reusable InvestmentSelect control.
 public class InvestmentSelect extends Select {

     private static final List INVESTMENT_OPTIONS = new ArrayList();

     static {
         OptionGroup property = new OptionGroup("Property");
         property.add(new Option("Commercial Property", "Commercial"));
         property.add(new Option("Residential Property", "Residential"));
         INVESTMENT_OPTIONS.add(property);

         OptionGroup securities = new OptionGroup("Securities");
         securities.add(new Option("Bonds"));
         securities.add(new Option("Options"));
         securities.add(new Option("Stocks"));
         INVESTMENT_OPTIONS.add(securities);
     }

     public InvestmentSelect(String label) {
         super(label);
         setOptionList(INVESTMENT_OPTIONS);
     }
 }

 public class InvestmentsPage extends Page {

     public Form form = new Form();

     private Select investmentsSelect = new InvestmentsSelect("investments");;

     public InvestmentsPage() {
         investmentsSelect.setMultiple(true);
         investmentsSelect(7);
         form.add(investmentsSelect);

         form.add(new Submit("ok", "  OK  "));
     }

     ..
 } 
Rendered HTML:
 
See also the W3C HTML reference: OPTION

See Also:
Select, OptionGroup, Serialized Form

Field Summary
static Option EMPTY_OPTION
          The empty select empty option.
protected  String label
          The Options display label.
protected  String value
          The Option value.
 
Constructor Summary
Option(Object value)
          Create an Option with the given value.
Option(Object value, Object label)
          Create an Option with the given value and display label.
 
Method Summary
 String getLabel()
          Return the Option display label.
 String getTag()
          Return the Option's html tag: option.
 String getValue()
          Return the Option value.
 void render(Select select, HtmlStringBuffer buffer)
          Return a HTML rendered Option string.
 String renderHTML(Select select)
          Deprecated. use render(org.apache.click.control.Select, org.apache.click.util.HtmlStringBuffer) instead
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_OPTION

public static final Option EMPTY_OPTION
The empty select empty option.


label

protected final String label
The Options display label.


value

protected final String value
The Option value.

Constructor Detail

Option

public Option(Object value,
              Object label)
Create an Option with the given value and display label.

Note: the specified value and label will be converted to a String.

Parameters:
value - the Option value
label - the Option display label

Option

public Option(Object value)
Create an Option with the given value. The value will also be used for the display label.

Note: the specified value will be converted to a String.

Parameters:
value - the Option value and display label
Method Detail

getTag

public String getTag()
Return the Option's html tag: option.

Returns:
the Option's html tag

getLabel

public String getLabel()
Return the Option display label.

Returns:
the Option display label

getValue

public String getValue()
Return the Option value.

Returns:
the Option value

render

public void render(Select select,
                   HtmlStringBuffer buffer)
Return a HTML rendered Option string.

Parameters:
select - the parent Select
buffer - the specified buffer to render to

renderHTML

public String renderHTML(Select select)
Deprecated. use render(org.apache.click.control.Select, org.apache.click.util.HtmlStringBuffer) instead

Return a HTML rendered Option string.

Parameters:
select - the parent Select
Returns:
rendered HTML Option string