0

I have VF page with 3 multi-select picklists and dependents.

"Multi Indication Level 1" is controlling multi-select picklist. "Multi Indication Level 2" is dependent on "Multi Indication Level 2". "Multi Indication Level 3" dependent on "Multi Indication Level 3".

So far, I am able to enter data on the page and select picklist values and save the record. Working very fine.

To display an existing record or edit the record, I want to display selected picklist values on these fields - "Multi Indication Level 1", 2 and 3.

If I assign one value it is working, the value displayed as selected. MultiPickListIndicationLevel1 = 'Blood';

If assign 2 values, it is not displaying as selected. I've tried both:

MultiPickListIndicationLevel1 = 'Blood, Cancer';

MultiPickListIndicationLevel1 = 'Blood; Cancer';

Below is the code snippet of VF page and controller.

Visualforce

<apex:selectList id="MIL1" value="{!MultiPickListIndicationLevel1}" Label="Multi Indication Level 1" multiselect="true" size="5">
        <apex:selectOptions value="{!MultiIndicationLevel1}"/>    
        <apex:actionSupport rerender="MIL2, MIL3" event="onchange"/>
</apex:selectList>

<apex:selectList id="MIL2" value="{!MultiPickListIndicationLevel2}" Label="Multi Indication Level 2" multiselect="true" size="5">
        <apex:selectOptions value="{!MultiIndicationLevel2}"/>   
        <apex:actionSupport rerender="MIL3" event="onchange"/>
</apex:selectList>    

<apex:selectList id="MIL3" value="{!MultiPickListIndicationLevel3}" Label="Multi Indication Level 3" multiselect="true" size="5">
        <apex:selectOptions value="{!MultiIndicationLevel3}"/>   
</apex:selectList>        

Controller

public string MultiPickListIndicationLevel1{get; set;}
public string MultiPickListIndicationLevel2{get; set;}
public string MultiPickListIndicationLevel3{get; set;}


public List<SelectOption> getMultiIndicationLevel1(){
    system.debug('Inside getMultiIndicationLevel1');
    List<SelectOption> options = new List<SelectOption>();
    options.add(new SelectOption('UnKnown','--UnKnown--'));
    system.debug('inside IndLeve1and2.keySet(): ' + IndLeve1and2.keySet());
    for(string IndLevel1 : new List<string>(IndLeve1and2.keySet()))
    {
        system.debug('inside IndLevel1' + IndLevel1);
        if(IndLevel1 <> null && IndLevel1 <> '')
            options.add(new SelectOption(IndLevel1, IndLevel1));
    }    
    system.debug('inside options: ' + options);
    return options;
}

public List<SelectOption> getMultiIndicationLevel2(){

    List<SelectOption> options = new List<SelectOption>();
    if(MultiPickListIndicationLevel1 == null || MultiPickListIndicationLevel1 == '[UnKnown]')
    {    
        options = null;
        return options;
    }        
    options.add(new SelectOption('UnKnown','--UnKnown--'));
    List<string> selectedPLvalues = MultiPickListIndicationLevel1.substring(1, MultiPickListIndicationLevel1.length()-1).split(', ');
    for(string selectedPLValue : selectedPLvalues)
    {
        if(IndLeve1and2.get(selectedPLValue) <> null)
        {    
            for(string DependPL : IndLeve1and2.get(selectedPLValue))
            {
                options.add(new SelectOption(DependPL, DependPL));
            }
        }    

    }    

    return options;             
}

public List<SelectOption> getMultiIndicationLevel3(){

    List<SelectOption> options = new List<SelectOption>();
    if(MultiPickListIndicationLevel2 == '[]' || MultiPickListIndicationLevel2 == null  || MultiPickListIndicationLevel2 == '[UnKnown]'
      || MultiPickListIndicationLevel1 == '[UnKnown]' || 
       (MultiPickListIndicationLevel1 <> MultiPickListIndicationLevel1OLDVAL && MultiPickListIndicationLevel1 <> null))
    {    
        options = null;
        MultiPickListIndicationLevel1OLDVAL = MultiPickListIndicationLevel1; 
        return options;
    }

    MultiPickListIndicationLevel1OLDVAL = MultiPickListIndicationLevel1;            
    options.add(new SelectOption('UnKnown','--UnKnown--'));
    List<string> selectedPLvalues = MultiPickListIndicationLevel2.substring(1, MultiPickListIndicationLevel2.length()-1).split(', ');

    for(string selectedPLValue : selectedPLvalues)
    {
        if(IndLeve2and3.get(selectedPLValue) <> null)
        {    
            for(string DependPL : IndLeve2and3.get(selectedPLValue))
            {
                options.add(new SelectOption(DependPL, DependPL));
            }
        }    

    }    
    return options;             


}

Questions Answers: Expected Pickist values for MultiPickListIndicationLevel1 are "Blood" "Cancer". I tried assigning value to variable MultiPickListIndicationLevel1 in controller. It is not working.

  • see a related question here. Try removing the spaces, something like MultiPickListIndicationLevel1 = 'Blood;Cancer'; – battery.cord Nov 1 '16 at 15:47
1

Where are these picklist values being saved to?

If you want them to display on edit, you will have to modify your getter method to populate the MultiPickListIndicationLevel* variable.

I.e.

public string MultiPickListIndicationLevel1{
    get {
        return indicatorLevel1;
    }
    set;
}

or, set it in your constructor

public YourVFController() {
    // get value of indicatorLevel1 somehow
    MultiPickListIndicationLevel1 = indicatorLevel1;
}
  • i tried setting the variable in controller it is not working – Razu Nov 1 '16 at 15:26
  • @Razu can you edit your post to be more specific than "not working"? That doesn't give answers much to work with – battery.cord Nov 1 '16 at 15:29
  • @battery.cord, updated with specific question. – Razu Nov 1 '16 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.