3

I currrently have a multi-select SelectList which whose options I am creating through a query. I now want to change it into a multi-select picklist with dual-columns. I am attempting to use this method as guidance :

Visual Force multi-select picklist

I am adapting my current code to somewhat fit that, and currently I have this :

public class MycontrollerSFDCBETA2{
public Account selectedUser { get; set; }
String contractid;
public Contract_Overview__c contract{get;set;}
public string relatedAccount{get;set;}
public string names{get;set;}
public string accountid{get;set;}
public Name contractnew{get;set;}
public string selectedaccountid{get;set;}
public String message { get; set; }

public List<String> selectedstring {get;set;}
public List<SelectOption> selectedsubs { get; set; }

public MycontrollerSFDCBETA2(apexpages.standardcontroller controller)
    {
    selectedsubs = new list<SelectOption>();
    List<String> selectedstring = new list<String>();

    contract = new Contract_Overview__c();
    contractid=system.currentpagereference().getparameters().get('id');
        if(contractid!=null)
        {
            contract=[select account__c,Subsidiaries_On_Contract__c from Contract_Overview__c  where id =:contractid];
            relatedAccount=Contract.account__C;
        }
    }

public pageReference  execute()
    {
    accountid=contract.Account__c;
    System.debug('########'+accountid);
    return null;
    }

public list<selectoption> getitems()
    {

    List<selectoption> options= new list<selectoption>();


    if(accountid != null)
        {
            account a =[select name , (select name from Subsidiaries_and_Brands__r) from account where id =:accountid];
    for(SubsidiariesAndBrands__c s : a.Subsidiaries_and_Brands__r)
                {
                options.add(new SelectOption(s.name,s.name));
                }
        }
    else
        options.add(new SelectOption('None','None'));
        return options;

    }

public void save()
    {

    System.debug('********************************' + names);
    System.debug('********************************' + selectedsubs);

    for(SelectOption so : selectedstring)
    {
       system.debug('Select vals ' + so.getValue());
       selectedstring.add(so.getValue());
    }

    contract.Subsidiaries_On_Contract__c= names;




    insert contract;
    contract=new Contract_Overview__c  ();
    System.debug('********************************' + contract);
       }          
    }

this line :

contract.Subsidiaries_On_Contract__c= names;

Will ultimately change with the picklist. That is what I am using now with the SelectList. But now I will only use names list to populate the left column (options) of the picklist. I need to use the value gathered from the right column of the picklist. I'm not sure how to do that. I don't know if I am properly setting up that right column list (SelectedSubs). I'm trying to turn it into a multi-value string with this :

for(SelectOption so : selectedstring)
    {
       system.debug('Select vals ' + so.getValue());
       selectedstring.add(so.getValue());
    }

I would be using the list SelectedSubs in the VF page as the value of the right picklist column :

<apex:pageBlock title="Subsidiaries">
        <c:MultiselectPicklist leftLabel="Available Subsidiaries"
            leftOptions="{!names}"
            rightLabel="Selected Subsidiaries"
            rightOptions="{!selectedSubs}"
            size="14"
            width="150px"/>
        <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>

I would then try to put it into a field. but I'm not sure if that is the correct approach. I'm also getting an error from those lines ("Loop variable must be of type String").

Can anybody give me some feedback on this ? Should this work ?

Thank you very much for your help and effort. I really appreciate it.

3 Answers 3

3

I've had simliar requirements and the jQuery Multi-Select works fantastically well for this. In particular the filtered version is amazing if you have a lot of options to choose from.

Multi-Select w/Filters

Multi-Select w/Filters

3
  • Thanks for the response Ralph. I put a comment under the other one I got which was also taking the jquery route. If you've got anything you can add to that comment I'd love to hear it. I'm totally stumped here.
    – Zoom_v
    Apr 11, 2013 at 13:15
  • I have figured this out and will be posting the working code later today sometime. I just wanted to let you know to make sure you didn't waste your own time looking at this any further. Thank you for your input. I really appreciate it.
    – Zoom_v
    Apr 11, 2013 at 15:28
  • btw - that was a really cool solution you showed here. I may end up using it one day if I need a filter for a long list of options.
    – Zoom_v
    Apr 11, 2013 at 15:33
1

The Multiselect Picklist component is a decent solution for what you want.

0
0

I'd take a look at this post for some pointers: http://www.tgerm.com/2012/01/ipad-multiselect-picklist-jquery-plugin.html

It's easy to setup, is re-usable and works really well...

3
  • Thank you very much for the response.I really was hoping to not go the route of jquery because I've invested so much time into this one and I feel as though I'm so close right now. It's really frustrating because I've gotten to the point where I can get the Available Options put into the left column, and to select them and move them into the Selected right column.All I need to do now is to capture those selections, put them into a list successfully and then properly save them in a field.That part has stumped me. Thanks again for the response.If you've got any ideas on that please let me know.
    – Zoom_v
    Apr 11, 2013 at 13:13
  • I have figured this out and will be posting the working code later today sometime. I just wanted to let you know to make sure you didn't waste your own time looking at this any further. Thank you for your input. I really appreciate it.
    – Zoom_v
    Apr 11, 2013 at 15:28
  • btw - I will probably need to re-visit that solution when I will be converting my application to iPad.
    – Zoom_v
    Apr 11, 2013 at 15:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .