You need to sign in to do that
Don't have an account?
Ravi Rao Arrabelli
Pass the Selected Values from Multi-select in Visualforce to the Custom Controller
Hi All,
I'm building a custom search, in which multi-select is one of the filter criteria. I have built the following code and used dynamic soql for this purpose:
vf page code:
<apex:selectlist multiselect="True" size="4" value="{!businessLines}" >
<apex:selectOptions value="{!busLinesLs}" />
</apex:selectlist>
Custom Controller Code:
public List<string> businessLines{get;set;}
public List<SelectOption> busLinesLs{
get{
if(busLinesLs==null){
busLinesLs = new List<SelectOption>();
Schema.DescribeFieldResult field = CustomObj__c.CustomField__c.getDescribe();
for (Schema.PickListEntry f: field.getPickListValues())
busLinesLs.add(new SelectOption(f.getValue(),f.getLabel()));
}
return busLinesLs;
}
set;
}
if(!businessLines.isempty()){
boolean flag = False;
system.debug('----------'+ businessLines);
soqlStr += 'AND (';
for(String str: businessLines){
if(flag){
soqlStr += ' OR ';
}
soqlStr += ' CustomField__c INCLUDES (\''+str+'\')';
flag = True;
}
soqlStr += ')';
}
I'm able to populate the picklist values in the page, but I think the highlighted values are not getting passed back to the controller. Can someone, please help me.
Thanks in Advance.
I'm building a custom search, in which multi-select is one of the filter criteria. I have built the following code and used dynamic soql for this purpose:
vf page code:
<apex:selectlist multiselect="True" size="4" value="{!businessLines}" >
<apex:selectOptions value="{!busLinesLs}" />
</apex:selectlist>
Custom Controller Code:
public List<string> businessLines{get;set;}
public List<SelectOption> busLinesLs{
get{
if(busLinesLs==null){
busLinesLs = new List<SelectOption>();
Schema.DescribeFieldResult field = CustomObj__c.CustomField__c.getDescribe();
for (Schema.PickListEntry f: field.getPickListValues())
busLinesLs.add(new SelectOption(f.getValue(),f.getLabel()));
}
return busLinesLs;
}
set;
}
if(!businessLines.isempty()){
boolean flag = False;
system.debug('----------'+ businessLines);
soqlStr += 'AND (';
for(String str: businessLines){
if(flag){
soqlStr += ' OR ';
}
soqlStr += ' CustomField__c INCLUDES (\''+str+'\')';
flag = True;
}
soqlStr += ')';
}
I'm able to populate the picklist values in the page, but I think the highlighted values are not getting passed back to the controller. Can someone, please help me.
Thanks in Advance.
Please find an example here:
Please do let me know if it helps.
Regards,
Mahesh
If possible please paste your full code and also use the above panel to copy the code (< >) so that it will be easy to understand the code.
Regards,
Mahesh
Also, tried to copy the code through the (<>) tab.. but its still not better.
The above are the complete codes and you can search for the part of the code which I posted in my first post (question).
I figured it out.. I was collecting the selected values (for another Picklist) through the javascript instead of storing directly in a custom control variable