+ Start a Discussion
Venky1219Venky1219 

Problem in binding picklist type field using inputfield

Hi,

I am using inputfield to populate picklist on my page but when I select a value and save its not binding, controller not able get value which is selected.
 
<apex:pageBlockSection  >
    <apex:inputField value="{!country.Languagecode__c}"/>
    <apex:pageBlockSectionItem >
        <apex:CommandButton value="Save" action="{!save}"/>
    </apex:pageBlockSectionItem> 
</apex:pageBlockSection>
 
public class CostomController{
public Country__c country{set;get;}
public CustomController(){
    country = new Country__c();
}
 public PageReference save(){
   
   System.debug('selected value:' + country.Languagecode__c);
   return null;
 }

}
Above debug statement returning " selected value:null "
 
Prerna BhallaPrerna Bhalla
you have to use standerdcontroller="Country__c" in <apex page> to fetch selected value in country.Languagecode__c
Mahesh DMahesh D
Hi Venky,

Please find the below code:
 
<apex:page controller="CustomControllerOne">
    <apex:form>
        <apex:pageMessages></apex:pageMessages>
        <apex:pageBlock>
            <apex:pageBlockSection  >
                <apex:inputField value="{!country.Name}"/>
                <apex:inputField value="{!country.Languagecode__c}"/>
                <apex:pageBlockSectionItem >
                    <apex:CommandButton value="Save" action="{!save}"/>
                </apex:pageBlockSectionItem> 
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

ControllerClass:
 
public class CustomControllerOne {
    public Country__c country{set;get;}

    public CustomControllerOne() {
        country = new Country__c();
    }
    
    public PageReference save() {
        insert country;
        System.debug('selected value:' + country.Languagecode__c);
        return new PageReference('/'+country.Id);
    }
}

I also tested the code in environment and everything looks good.

Please do let me know id helps you.

Regards,
Mahesh