Type 5:Usage of Dynamic picklist in vf & Apex


<apex:page controller="dynamicpickone" sidebar="false" showHeader="false">

<apex:form >
 <apex:selectList id="selectpick" size="1" value="{!selectedValue}">
 <apex:selectOptions value="{!pickOptions}"/>
 <apex:actionSupport event="onchange" reRender="one"/>
 </apex:selectList>

<apex:outputPanel id="one">Selected Value is:
 <apex:outputText value="{!selectedValue}" />
 </apex:outputPanel>
 </apex:form>
 </apex:page>

Controller:

public class dynamicpickone{
//Constructor
public dynamicpickone() {

Parent = new Parent__c();
pickOptions = new List<SelectOption>();

// Use DescribeFieldResult object to retrieve commodities field.
// statusFieldDescription=sFD
Schema.DescribeFieldResult sFD = Parent__c.commodities__c.getDescribe();

// For each picklist value, create a new select option
//picklistEntry=plE
for (Schema.Picklistentry plE:sFD.getPicklistValues()){

pickOptions.add(new SelectOption(plE.getValue(),plE.getLabel()));

// obtain and assign default value
//if (picklistEntry.defaultValue){
// Parent.commodities__c = pickListEntry.getValue();
// }
}
}

Type 5:Usage of Dynamic picklist in vf & Apex

Type 5:Usage of Dynamic picklist in vf & Apex

Advertisements