How to Use Select options in Visualforce page?
Selectoption object specifies one of the possible values for visualforce select checkboxes, select list, select radio component.
It consist of label that is displayed to the end user, and the value that will be written to the controller.
Note:- The SelectOption can be displayed in the disable state.
Constructors:
We have 2 types of constructors in this class
Instantiating
SelectOption one = bew SelectOpton (value(String), label(String), IsDisabled(true/false));
If isDisabled is true, the option is disabled . We can not select that value.
SelectOption one = new SelectOption(value, label)
Value as String
Label as String
Methods:
- getDisabled()
Returns the current value of the SelectOption object's isDisabled attribut - getEscapeItem()
- Returns the current value of the SelectOption object's itemEscaped attribute.
- getLabel()
Returns the option label that is displayed to the user.
Ex: one.getLabel();
output: : One
- 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.
Ex: one.setDisabled(false);
- 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.
Example:
Controller Class:
public class SelectOptionExample {
String[] countries = new String[]{};
public PageReference test() {
return null;
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico'));
return options;
}
public String[] getCountries() {
return countries;
}
public void setCountries(String[] countries) {
this.countries = countries;
}
}
VF Page:
<apex:page controller="SelectOptionExample">
<apex:form >
<apex:selectCheckboxes value="{!countries}">
<apex:selectOptions value="{!items}"/>
</apex:selectCheckboxes><br/>
<apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
</apex:form>
<apex:outputPanel id="out">
<apex:actionstatus id="status" startText="testing...">
<apex:facet name="stop">
<apex:outputPanel >
<p>You have selected:</p>
<apex:dataList value="{!countries}" var="c">{!c}</apex:dataList>
</apex:outputPanel>
</apex:facet>
</apex:actionstatus>
</apex:outputPanel>
</apex:page>
Once you select the options and click on test it will display the selected checkboxes details.
That's it....
1 comments:
Đơn vị chuyên nhận order đặt mua hàng phụ kiện thời trang
Công ty chuyên nhận order đặt mua hàng thời trang ở Quảng Châu
Công ty chuyên nhận order đặt mua hàng quần áo ở Quảng Châu
Post a Comment