function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Big EarsBig Ears 

Custom Mult-Select Picklist - problems

I'm trying to build a multi-select picklist within an <apex:pageblocktable>, but I'm only ever getting null values out of it.

 

I've used an <apex:selectList> component with "multiselect=true". The component value attribute relates to a list of strings in a custom class, so I can't use the <apex:inputfield> component for visual styling.

 

The component that is rendered on the page doesn't have any right-hand box to indicate selection of the options. Should it? Do I need to personally style a multi-select picklist component?

 

Are there any rules for using multi-select that I should know?

 

Please help, I've no idea where to go from here

 

With thanks,

Andy

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

This is because you have the immediate attribute set to true on the command button.  That means that no validation is run, nor is the page state updated with any changes that have been made.  Essentially its cancelling out of your changes.

 

Change that to false and you should be good to go. 

All Answers

bob_buzzardbob_buzzard

An apex selectlist is a bit of a halfway house when it comes to picklists.  Its not a dropdown (like the standard picklist) as that only allows a single selection.  However, the multiple select just highlights multiple entries in the list.

 

I ended up creating my own VF component that comes close to the inputfield version of a multi-select pick list.  It consisted of two select lists side by side - one representing available and one representing chosen.  Buttons underneath to move items around.  It was a reasonable amount of code, but was probably complicated by the fact that I needed to have three of these on a single page.

Big EarsBig Ears

Thanks, Bob.

 

I hadn't realised that there wasn't an out-of-the-bow solution for multi-select. This has fundamentally altered the project I'm working on.

 

Thank you for your time. I'll look at creating my own. One problem I'm having, is I'm unsure how to get the multi-select list to communicate the values that have been selected to the controller. Whenever I try and debug the value of the list, I just get null. I'm doing the standard{get; set;} business with the variable, but I just get a null.

 

Do you know any way around that?

 

With thanks,

Andy

 

bob_buzzardbob_buzzard
If your selectlist allows multiple selects, it needs to be backed by an array of strings. That's always worked for me.
Big EarsBig Ears

Thanks Bob,

 

To be sure, it should be possible to simply click on an option for the controller to count it as "selected" as long as things are all set up? I've got the variable set up as an array of strings and I'm really confused. Could I ask you to take a look?

 

 

<apex:page controller="TableControllerTest">
<apex:form >
<apex:pageblock title="Assessment & Follow-up Questions">
<apex:pageblocktable id="TheTable" value="{!DealAssessments}" var="Ass"> "DealAssessments" is a collection from a custom class, the class includes an OpportunityLineItem and some custom variables

<apex:column HeaderValue="Assessment">
{!Ass.assessment.pricebookEntry.Name}
</apex:column>
<apex:column HeaderValue="Quote Reference">
{!Ass.assessment.Supplier_Quote_Reference__c}
</apex:column>
<apex:column HeaderValue="Related to:">
<apex:selectList value="{!Ass.MyStringArray}" multiselect="true" > - here's the multi-select picklist, it refers to the array of strings "MyStringArray"

<apex:SelectOptions value="{!ScopesIncluded}" />
</apex:selectList>
</apex:column>
</apex:pageblocktable>
</apex:pageblock>

<apex:commandbutton action="{!Push}" value="Push" immediate="true"/> - this is just to cause the debugger to run

</apex:form>
</apex:page>

 

 

 

 

 

public with sharing class TableControllerTest {
List<VFassessment> DealAssessments;
List<string> productsSold;

public class MyCustomClass{
public OpportunityLineItem assessment {get; set;}

public string[] MyStringArray{get; set;}
}

public List<MyCustomClass> getDealAssessments(){
if(DealAssessments == null){
DealAssessments = new List<VFassessment>();
VFassessment vfass;

for(OpportunityLineItem oli : LIST OF LINE ITEMS FROM A SPECIFIC PRODUCT FAMILY){
vfass = new VFassessment();
vfass.assessment = oli;
vfass.MyStringArray = new List<string>();
DealAssessments.add(vfass);
}
}

return DealAssessments;
}

public pageReference Push(){
system.debug('BUTTON PUSHED!');

for(VFassessment vfa : getDealAssessments()){

system.debug('DEBUG - '+vfa.certificateScope);

}


return null;
}

public List<SelectOption> getScopesIncluded(){
List<SelectOption> options = new List<SelectOption>();

for(string s: LIST OF STRINGS SUPPLIED ELSEWHERE IN THE CODE){
options.add(new SelectOption(s,s));
}

return options;
}

}

 

 When I hit the "Push" button, the debugger runs, and I get a debug log. If I've included values in the initialisation of the List<MyCustomClass>, they show up in the table columns and the debug log. Unfortunately, if I highlight any of the rows in the select list and then hit the button, none of the new selected values show up in the debug log.

 

I'm sure it's just me being really stupid?

 

With thanks,

Andy

 

bob_buzzardbob_buzzard

This is because you have the immediate attribute set to true on the command button.  That means that no validation is run, nor is the page state updated with any changes that have been made.  Essentially its cancelling out of your changes.

 

Change that to false and you should be good to go. 

This was selected as the best answer
Big EarsBig Ears

Bob,

 

Thank you. I'd thought the the immediate="true" attribute only affects the validation rules, but not values being passed into the controller.

 

Thanks for your time, again.

 

Andy

niteshdelniteshdel

Bob can please post the code for the component. It will be very helpful. I need this in my project very urgently.

 

 

Thanks