SelectOption Class

A SelectOption object specifies one of the possible values for a Visualforce selectCheckboxes, selectList, or selectRadio component.

System

SelectOption consists of a label that is displayed to the end user, and a value that is returned to the controller if the option is selected. A SelectOption can also be displayed in a disabled state, so that a user cannot select it as an option, but can still view it.

In a custom controller or controller extension, you can instantiate a SelectOption in one of the following ways:

  • where value is the String that is returned to the controller if the option is selected by a user, label is the String that is displayed to the user as the option choice, and isDisabled is a Boolean that, if true, specifies that the user cannot select the option, but can still view it.

  • where value is the String that is returned to the controller if the option is selected by a user, and label is the String that is displayed to the user as the option choice. Because a value for isDisabled is not specified, the user can both view and select the option.

The following example shows how a list of SelectOptions objects can be used to provide possible values for a selectCheckboxes component on a Visualforce page. In the following custom controller, the getItems method defines and returns the list of possible SelectOption objects:

In the following page markup, the <apex:selectOptions> tag uses the getItems method from the controller above to retrieve the list of possible values. Because <apex:selectOptions> is a child of the <apex:selectCheckboxes> tag, the options are displayed as checkboxes:

The following are constructors for SelectOption.

Creates a new instance of the SelectOption class using the specified value and label.

public SelectOption(String value, String label)

  • value: Type: String The string that is returned to the Visualforce controller if the option is selected by a user.
  • label: Type: String The string that is displayed to the user as the option choice.

Creates a new instance of the SelectOption class using the specified value, label, and disabled setting.

public SelectOption(String value, String label, Boolean isDisabled)

  • value: Type: String The string that is returned to the Visualforce controller if the option is selected by a user.
  • label: Type: String The string that is displayed to the user as the option choice.
  • isDisabled: Type: Boolean If set to true, the option can’t be selected by the user but can still be viewed.

The following are methods for SelectOption. All are instance methods.

  • getDisabled()

    Returns the current value of the SelectOption object’s isDisabled attribute.

  • getEscapeItem()

    Returns the current value of the SelectOption object’s itemEscaped attribute.

  • getLabel()

    Returns the option label that is displayed to the user.

  • getValue()

    Returns the option value that is returned to the controller if a user selects the option.

  • setDisabled(isDisabled)

    Sets the value of the SelectOption object’s isDisabled attribute.

  • setEscapeItem(itemsEscaped)

    Sets the value of the SelectOption object’s itemEscaped attribute.

  • setLabel(label)

    Sets the value of the option label that is displayed to the user.

  • setValue(value)

    Sets the value of the option value that is returned to the controller if a user selects the option.

Returns the current value of the SelectOption object’s isDisabled attribute.

public Boolean getDisabled()

Type: Boolean

If isDisabled is set to true, the user can view the option, but cannot select it. If isDisabled is set to false, the user can both view and select the option.

Returns the current value of the SelectOption object’s itemEscaped attribute.

public Boolean getEscapeItem()

Type: Boolean

If itemEscaped is set to true, sensitive HTML and XML characters are escaped in the HTML output generated by this component. If itemEscaped is set to false, items are rendered as written.

Returns the option label that is displayed to the user.

public String getLabel()

Type: String

Returns the option value that is returned to the controller if a user selects the option.

public String getValue()

Type: String

Sets the value of the SelectOption object’s isDisabled attribute.

public Void setDisabled(Boolean isDisabled)

Type: Void

If isDisabled is set to true, the user can view the option, but cannot select it. If isDisabled is set to false, the user can both view and select the option.

Sets the value of the SelectOption object’s itemEscaped attribute.

public Void setEscapeItem(Boolean itemsEscaped)

Type: Void

If itemEscaped is set to true, sensitive HTML and XML characters are escaped in the HTML output generated by this component. If itemEscaped is set to false, items are rendered as written.

Sets the value of the option label that is displayed to the user.

public Void setLabel(String label)

Type: Void

Sets the value of the option value that is returned to the controller if a user selects the option.

public Void setValue(String value)

Type: Void