net.sf.click.control
Class Option

java.lang.Object
  extended bynet.sf.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("Commerical 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.setMutliple(true);
         investmentsSelect(7);
         form.add(investmentsSelect);

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

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

Author:
Malcolm Edgar
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, String label)
          Create an Option with the given value and display label.
Option(String value)
          Create an Option with the given value.
 
Method Summary
 String getLabel()
          Return the Option display label.
 String getTag()
          Return the Options'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(net.sf.click.control.Select, net.sf.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,
              String label)
Create an Option with the given value and display label.

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

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

Option

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

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

getTag

public String getTag()
Return the Options'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(net.sf.click.control.Select, net.sf.click.util.HtmlStringBuffer) instead

Return a HTML rendered Option string.

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