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.
MultiPickListIndicationLevel1 = 'Blood;Cancer';