You need to sign in to do that
Don't have an account?
Manoj Maraka 18
Issue working with Multiselect picklists
Hi All,
I am very new to Salesforce. I am trying to implement 2 multiselect picklists, Left picklist takes contacts from Contact object and on clicking ">>" button selected contacts should be moved from left picklist to right picklist. And on hitting 'Save', a message should be displayed saying so and so contacts are selected.
The issue here is the contacts are not getting added in right picklist. I dont know where I am going wrong. Could anyone please help? Here's the code I used.
VF Page:
Controller:
I am very new to Salesforce. I am trying to implement 2 multiselect picklists, Left picklist takes contacts from Contact object and on clicking ">>" button selected contacts should be moved from left picklist to right picklist. And on hitting 'Save', a message should be displayed saying so and so contacts are selected.
The issue here is the contacts are not getting added in right picklist. I dont know where I am going wrong. Could anyone please help? Here's the code I used.
VF Page:
<apex:page controller="multiselect2"> <apex:form > <apex:pageBlock > <apex:outputLabel value=" Available List"> </apex:outputLabel> <apex:panelGrid columns="3" id="abcd"> <apex:selectList id="sel1" value="{!leftselected}" multiselect="true" style="width:150px" size="7"> <apex:selectOptions value="{!unselectedvalues}" /> </apex:selectList> <apex:panelGroup > <br/> <apex:commandbutton value=">>" action="{!selectclick}" reRender="abcd"></apex:commandbutton> <br/><br/> <apex:actionRegion > <apex:commandbutton value="<<" action="{!unselectclick}" reRender="abcd"> </apex:commandbutton> </apex:actionRegion> </apex:panelGroup> <apex:selectList id="sel2" value="{!rightselected}" multiselect="true" style="width:150px" size="7"> <apex:selectOptions value="{!rightselected}" /> </apex:selectList> </apex:panelGrid> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>
Controller:
public class multiselect2 { Public List<Contact> leftselected{get;set;} Public List<Contact> rightselected{get;set;} Set<Contact> leftvalues = new Set<Contact>(); Set<Contact> rightvalues = new Set<Contact>(); public multiselect2(){ List<Contact> ov = [SELECT Id, Name FROM Contact]; Set<Contact> originalValues = new Set<Contact>(ov); leftselected = new List<Contact>(); rightselected = new List<Contact>(); leftvalues.addAll(originalValues); } public PageReference selectclick(){ rightselected.clear(); for(Contact c : leftselected){ leftvalues.remove(c); rightvalues.add(c); } return null; } public PageReference unselectclick(){ leftselected.clear(); for(Contact c : rightselected){ rightvalues.remove(c); leftvalues.add(c); } return null; } public List<SelectOption> getunSelectedValues(){ List<SelectOption> options = new List<SelectOption>(); List<Contact> tempList = new List<Contact>(); tempList.addAll(leftvalues); tempList.sort(); for(Contact c : tempList) options.add(new SelectOption(c.id,c.name)); return options; } public List<SelectOption> getSelectedValues(){ List<SelectOption> options1 = new List<SelectOption>(); List<Contact> tempList = new List<Contact>(); tempList.addAll(rightvalues); tempList.sort(); for(Contact c : tempList) options1.add(new SelectOption(c.id,c.name)); return options1; } public PageReference save() { return null; } }
Apex:
VF: Note: The values removed from right picklist are added back at the end of left picklist
Mark this as Best Answer, if this solves your problem.
All Answers
'>>' click is working properly but '<<' click is not setting rightselected value that is why unselect is not working (line 38 is not giving selcted value on right side) . Need to figure it out the reason or any someother alternative way .
I have modifed your code a bit, and tried to make it sleek. please have a look
Apex:
VF:
Mark this as Best Answer, if this solves your problem.
Your code gives following compile error. Error: Compile Error: Invalid constructor name: TestClass2 at line 7 column 12
Apex:
VF: Note: The values removed from right picklist are added back at the end of left picklist
Mark this as Best Answer, if this solves your problem.