function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hellos_ritzhellos_ritz 

Passing picklist values to controller

Hi,

 I want to pass the picklist values from visualforce page to the controller. I am using custom setting object.

The situation is that on the basis of the picklist value selected the depended picklist values need to be displayed. Both the picklists are the fields of the custom settings object. The rest of the logic is working fine when the selected picklist option is hardcoded. The only glitche is that data is not getting passed to the controller

The following is the line of code I am using for this:

 

System.debug('selectedMatCatValue..............'+selectedMatCatValue);
      selectedMatCatValue = system.currentPageReference().getParameters().get('selmatcatvalueref');
Please someone provide help in this case
Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

In order for that mechanism to work, you'd have to have re-request the page when the picklist value is chosen passing that parameter in the URL.

 

You would do better to back the input field on the page with the controller variable.

 

Can you post your VF page.

All Answers

bob_buzzardbob_buzzard

In order for that mechanism to work, you'd have to have re-request the page when the picklist value is chosen passing that parameter in the URL.

 

You would do better to back the input field on the page with the controller variable.

 

Can you post your VF page.

This was selected as the best answer
Prasanthi BPrasanthi B

Iam also involved in similar type of requirement.

 

Based on the selected picklist value, i need to run a query and display the result to the user.

 

Please check my code and suggest.

 

 

 

<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>
  <br></br>
  <br></br>
   Select Region of the user:
   <apex:selectList id="u" value="{!usr}" size="1" title="Users">
   <apex:selectOptions value="{!usrs}"></apex:selectOptions>
   </apex:selectList>
   <apex:pageBlockButtons >
  
<apex:commandButton value="GO" action="{!doSearch}">
               
    </apex:commandButton>
    </apex:pageBlockButtons>
    <apex:pageBlockTable value="{!Results}" var="names">
    </apex:pageBlockTable>
   <br></br>             
 
  </apex:pageblock>
  </apex:form>   
  </apex:page>

 

 

 

public class UserData {
PUBLIC String usr{get;set;}
PUBLIC List<selectOption> usrs;
List<User> results;
List<Id> userlist=new List<Id>();

   public UserData(ApexPages.StandardController controller)
   { 
     }
  
   public List<selectOption> getusrs()
  {
    List<selectOption> options = new List<selectOption>(); 
    options.add(new selectOption('', '- None -'));   
    FOR (User users : [SELECT Id,Region__c FROM User Order By Region__c Asc]) 
    {   
      options.add(new selectOption(users.Id, users.Region__c));
      userlist.add(users.Id);   
    }    
       return options; 
  } 
   public PageReference test() {
    return null;
  }
  
   public List<User> doSearch()
     {
       List<User> Userlist=new List<User>([select Name from User Where Id=:users.id]);

     //selected picklist value has to be    passed  to this query
       system.debug('USERSLISTFOR REGION$$$$'+results);
       }
      
   public List<User> getResults()
    {
        return results;
    }
 
 }