I need to take two SelectOption lists and create a third one which will be composed of the values which are in both lists.
I'm having trouble figuring out how to properly compare them in this code I have.
I've left out a good portion of the code in order to try and simplify it.
I need to compare the selectedSubs2 list to the getkeyTechValues list.
Here is the code :
selectedSubs2 = new list<SelectOption>();
String[] selectedvalues = selectedkeys.split(',');
for (String selectedvalue: selectedvalues)
{
selectedSubs2.add(new SelectOption(selectedvalue,selectedvalue));
}
public List<SelectOption> getkeyTechValues()
{
List<SelectOption> options=new List<SelectOption>();
options.add(new SelectOption('--None--','--None--'));
String[] picklistlines =new String[]{};
for (String item : selectedMulPickKeyTech.split(',') )
{
if (!selectedItems.contains(item))
{
//add it to your iist
options.add(new SelectOption(item,item));
}
}
return options;
}
}
//somehow I need to compare the selectedSubs2 list to the getkeyTechValues
//and make a 3rd SelectOption list of only the values which are in both
Thank you very much for your help. I really appreciate it.
Best Answer
Your controller will need to a lot of the work in terms of recalculating the third dropdown. I'm thinking the first and second select lists will call a method in your controller to clear out and re-generate the third dropdown, effectively creating a cascading or dependent drop down. See my controller example below.
Furthermore, you'll need to use an apex:actionFunction or call into the controller and rerender the visualforce page to pick up the changes incurred by calling the handleSelections method.
Hope this helps get you on the right track.