7

VF Page

<apex:selectList size="1" value="{!interaction.Company__c}" id="interactionCompany">
      <apex:selectOptions value="{!allCompanyOrgUnit}"/>
      <apex:actionSupport event="onchange" action="{!getAssociatedBusinessUnitsOrgs}" reRender="interactionBusinessUnit" immediate="true">
          <apex:param name="a" assignTo="{!comp}" value="{!Object.Company__c}"/>
      </apex:actionSupport>
</apex:selectList>                        
<apex:selectList size="1" value="{!Object.Business_Unit__c}" id="interactionBusinessUnit">
     <apex:selectOptions value="{!businessUnitOrgs}"/>
</apex:selectList>

Apex Code

public PageReference getAssociatedBusinessUnitsOrgs() {
    businessUnitOrgs = new List<SelectOption>();

    System.debug('Inside BUOrgUnit');
    System.debug(''+object.company__c);    

    return null;
}

3 Answers 3

1

In selectlist ,value parameter will hold the selected value by default,so if you want a Controller variable the define that in class(with get and set) and use it. Like below,

<apex:selectlist value="{!review}" >
            <apex:selectoptions value="{!countries}" />
</apex:selectlist>

in class,

public string review  {get;set;}

Have one get method for getting picklist values,

public List<SelectOption>  getCountries() {
    List<SelectOption> options = new List<SelectOption>();
    options.add('India','India');
    options.add('Nepal','Nepal');
    return options;
}

here countries will hold the picklist values. And review will hold selected value

1
  • I have to use the selected item's ID in method based on which i am displaying another dependent picklist. I am using standard controller for my object and in value saving object.fieldname.. Jun 26, 2015 at 5:11
0

Instead of using "actionSupport" use "actionFunction" and give it a try.

Please look at this post for related discussion.

https://stackoverflow.com/questions/13512907/get-id-of-selected-lookup-item

0

When you are creating the Map for allCompanyOrgUnit in controller you have to populate the Id as key and Name as the value.

Please find the below example. Here I have used the Map ListOfUser and populate Id and value UserOptionList.add(new SelectOption(u.Id , u.Name)); in the controller. So when the VF page will render as HTML in browser you can see the Ids (Shown in screenshot). Upon selecting an option from the dropdown the corresponding Id will be passed to controller. Hope this helps.

Page:

    <apex:page controller="userController">
        <apex:form>
            <apex:pageBlock>
                <apex:pageBlockSection>
                    <apex:OutputPanel >
                        <apex:selectList value="{!selecteduserId}" size="1" multiselect="false"  >
                            <apex:selectOptions value="{!ListOfUser}" />
                        </apex:selectList>
                    </apex:OutputPanel>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:form>
    </apex:page>

Controller:

public with sharing class userController{
    //This variable hold the id of  user which is selected by enduser from picklist
    public String selecteduserId {set;get;}
    //This var hold List of user
    public List<SelectOption> getListOfUser(){
        List<User> Users = [select id ,Username,name from user] ;
        List<SelectOption> UserOptionList = new List<SelectOption>();
        UserOptionList.add(new SelectOption( ' ' ,'---Select---'));
        for(User u : Users ){
            UserOptionList.add(new SelectOption(u.Id , u.Name));
        }
        return UserOptionList;
    }
    public userController(){
        selecteduserId ='';
    }
}

Screenshot: enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .