Reputation: 81
I have multiselect picklist and I want to get selected values for insert and update operation.
<apex:page standardController="Change_Request__c" sidebar="false" extensions="Change_RequestController">
<apex:selectList label="Select Pasenger(s)" value="{!Change_Request__c.Passenger_Name__c}" multiselect="true" onfocus="getSelectedID('{!$Component.empid}');" >
<apex:selectOptions value="{!pax}" />
</apex:selectList>
And this is my extension:
public class Change_RequestController {
private final Change_Request__c changer;
public List<selectOption> pax;
public Change_RequestController(ApexPages.StandardController controller) {
this.changer = (Change_Request__c)controller.getRecord();
}
public List<selectOption> getPax() {
List<selectOption> options = new List<selectOption>();
String fullName;
for (Passenger_Info__c p : [SELECT Id,First_Name__c,Name from Passenger_Info__c ]) {
fullName = (p.First_Name__c == null)?'':p.First_Name__c+' '+p.Name;
options.add(new selectOption(fullName, fullName));
}
return options;
}
public List<selectOption> setPax() {
List<selectOption> options = new List<selectOption>();
for (String pa : changer.Passenger_Name__c.split(',') ) {
options.add(new selectOption(pa, pa));
}
return options;
}
}
Upvotes: 0
Views: 9706
Reputation: 1189
Change controler to
public class Change_RequestController {
public Change_Request__c changer{get;set;}
public Change_RequestController(ApexPages.StandardController controller) {
this.changer = (Change_Request__c)controller.getRecord();
}
public List<selectOption> getPax() {
List<selectOption> options = new List<selectOption>();
String fullName;
for (Passenger_Info__c p : [SELECT Id,First_Name__c,Name from Passenger_Info__c ]) {
fullName = (p.First_Name__c == null)?'':p.First_Name__c+' '+p.Name;
options.add(new selectOption(fullName, fullName));
}
return options;
}
}
and page to
<apex:selectList label="Select Pasenger(s)" value="{!changer.Passenger_Name__c}" multiselect="true" onfocus="getSelectedID('{!$Component.empid}');" >
<apex:selectOptions value="{!pax}" />
</apex:selectList>
Upvotes: 0