+ Start a Discussion

Passing PickValue to a Variable in Controller method

Can anybody help me in resolving the below issue.


I have written a visualforce page consisting of picklist.When I select a value in the picklist the value should be passed to a variable in controller class.I am not getting the selected value in the variable.


/////////My Visualforce page



<apex:page StandardController="User" id="thePage" Extensions="UserData"> 

<apex:form >

<apex:pageBlock title="SelectUsers" id="USERSLIST" mode="edit">

<h1>Update Sales Co-ordinator for the users in Particular Region</h1>


Select Region of the User: <apex:inputField id="startMode" value="{!User.Region__c}" />


<apex:commandButton value="Search" action="{!doSearch}" status="myStatus">









//////My Controller


public class UserData {

 PUBLIC String usr{get;set;}

PUBLIC List<selectOption> usrs;

List<User> results=new List<User>();

List<Id> userlist=new List<Id>();

String Regionid;

String Region;

public UserData(ApexPages.StandardController controller)



public Pagereference doSearch()


//selected picklistvalue should be passed to the below query

results = [select Name from User Where id=:??????];

system.debug('USERSLISTFOR REGION$$$$'+results);

return null;



public List<User> getResults()


return results;





Can anyone please help me in resolving the issue.






Please provide a


Leon MorockiLeon Morocki



results = [select Name from User Where Region__c = :(((User)controller.getRecord()).Region__c)];


You also need to save the controller variable that is passed to the constructor for use in the above query.




Thank you for your reply.


Could you please elaborate on "save the controller variable that is passed to the constructor for use in the above query".


The constructor is an empty one and i am not using any variable that is assigned in the controller method.



Leon MorockiLeon Morocki

The constructor argument "ApexPages.StandardController controller" needs to be saved for later use in doSearch method:


private ApexPages.StandardController controller;

public UserData(ApexPages.StandardController controller)
    this.controller = controller;