+ Start a Discussion
Jugbeer BholaJugbeer Bhola 

Visualfore Remoting - Picklist definition and retrieval

I see examples of manipulating picklist with visualforce tags everywhere.  That is not what is necessary. Does anyone know how to define a pure HTML picklist on a visualforce page with no <apex:/> tags? The task is to use "remoting" which is a new concept to me.  I know how to call functions in a controller like this:
//Salutation Picklist
    public void CollectSalutation ()
    {
        Schema.DescribeFieldResult salutationFieldDescription = Contact.Salutation.getDescribe();
        SalutationOptions = new list<SelectOption>();
        
        for (Schema.Picklistentry picklistEntry : salutationFieldDescription.getPicklistValues())
        {
            SalutationOptions.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel()));
        }
    }
acct.PickListNames__c = document.getElementById('picklistNames').value;

Do I need to wrap these methods in something or create them solely in HTML for Javascript to access.  Any advice from the experts out there would be appreciated.
 
Lalit Karamchandani 27Lalit Karamchandani 27
Hi Brian Daul 22
With out remoting you can do like this easly
Controller code
public class mvpController{
	public List<SelectOption> optionsList{get;set;}
	public String selectedoptions{get;set;}
	
	public mvpController(){
		optionsList=new List<SelectOption>();
		optionsList=getPicklistValues('Account','Rating');
	}
	private List<SelectOption> getPicklistValues(String ObjectApi_name,String Field_name){ 
        List<SelectOption> options = new list<SelectOption>();
        Schema.SObjectType targetType = Schema.getGlobalDescribe().get(ObjectApi_name);//From the Object Api name retrieving the SObject
        Sobject Object_name = targetType.newSObject();
        Schema.sObjectType sobject_type = Object_name.getSObjectType(); //grab the sobject that was passed
        Schema.DescribeSObjectResult sobject_describe = sobject_type.getDescribe(); //describe the sobject
        Map<String, Schema.SObjectField> field_map = sobject_describe.fields.getMap(); //get a map of fields for the passed sobject
        List<Schema.PicklistEntry> pick_list_values=new List<Schema.PicklistEntry>();
        if(Test.isRunningTest()){
        }else{
             pick_list_values = field_map.get(Field_name).getDescribe().getPickListValues(); 
        }
        for (Schema.PicklistEntry a : pick_list_values) { //for all values in the picklist list
            options.add(new SelectOption(a.getValue(),a.getLabel()));//add the value  to our final list
        }
        return options ;
	}
}
page code
<apex:selectList multiselect="false" size="1"  value="{!selectedoptions}"  >
	   <apex:selectOptions value="{!optionsList}"/>
   </apex:selectList>