[SalesForce] Getting selected value from (dropdown) to a controller variable

I am working on a custom VF page for a case screen with extension controller class in use.

<apex:actionRegion >
  <apex:inputfield label="Action" value="{!case.Action__c}" id="Action" >
     <apex:actionSupport event="onchange" rerender="ProdFamilyModel" immediate="false" /> 
  </apex:inputfield> 
</apex:actionRegion>

I want the selected value from the input field assigned to a string variable in my extension class. I have searched a lot and was unable to get an answer.

Suppose in my dropdown there are two values, say "Apple","Orange". So if i select Apple, i want this name to be stores in a string variable.

Best Answer

I am extending @battery.cord's answer with an example as follows:

Visualforce

<apex:actionRegion >
  <apex:inputfield label="Action" value="{!caseObj.Action__c}" id="Action" >
     <apex:actionSupport event="onchange" rerender="ProdFamilyModel" action="{!passValueToController}" /> 
  </apex:inputfield> 
</apex:actionRegion>

Controller

public class ActionSupportController
{
    public String fieldValue {get; set;}
    public Case caseObj {get;set;}
    public void passValueToController()   
    {        
          fieldValue = caseObj.Action__c; //this will assign the selected value to Controller variable.
    }
}
Related Topic