+ Start a Discussion
NishaCNishaC 

Problem in splitting multiselect list

i have a multiselect list with values as this 

Days_collection__c = Monday am

                                        Monday pm

                                        Monday overnight 

                                        Tuesday am

                                                         pm

                                                         overnight

                                        Wednesday am

                                                               pm

                                                               overnight

and so on 

but i want to only week days from this list not with am,pm,overnight

but this is a multiselect list   so sometimes i have vallues like

        monday am,tuesday pm,wednesday,om,thrusday overnight,friday pm

how can i get only week days 

asish1989asish1989

HI

  will you check this.....

   I have defined a page which shows multiselect picklist and two Arrow mark image .You can check this 

   This is my page

<apex:page controller="multiselect">
    <apex:form >
        <apex:panelGrid columns="3" id="abcd">
            <apex:selectList id="sel1" value="{!leftSelected}" multiselect="true" style="width:100px" size="5">
                <apex:selectOptions value="{!unSelectedvalues}" />
            </apex:selectList>
                <apex:panelGroup >
                    <br/>
                    <apex:image value="{!$Resource.multiselected}">
                        <apex:actionSupport event="onclick" action="{!selectclick}" reRender="abcd"/>
                    </apex:image>
                    <br/><br/>
                    <apex:image value="{!$Resource.multiselected}">
                        <apex:actionSupport event="onclick" action="{!unSelectclick}" reRender="abcd"/>
                    </apex:image>
                </apex:panelGroup>
            <apex:selectList id="sel2" value="{!rightSelected}" multiselect="true" style="width:100px" size="5">
                <apex:selectOptions value="{!SelectedValues}" />
            </apex:selectList>
        </apex:panelGrid>
    </apex:form>
</apex:page>

 And My controller is 

public class Multiselect {

    Set<String> originalvalues = new Set<String>{'Monday am','Wendsday pm','Friday neight','Tuesday am'};
    public List<string>leftSelected {get;set;}
    public List<string> rightSelected{get;set;}
    Set<String> leftValues = new Set<String>();
    Set<String> rightValues = new Set<String>();
    
    public multiselect(){
        leftSelected = new List<String>();
        rightSelected = new List<String>();
        leftValues.addAll(originalValues);
    }
    
    public PageReference selectclick(){
        rightSelected.clear();
        for(String s : leftSelected){
            
            leftValues.remove(s);
//string spilting logic String st = s.substring(0,s.indexOf('y')+1); System.debug('##################SouvikTest#############'+st); rightValues.add(st); } return null; } public PageReference unSelectClick(){ leftselected.clear(); for(String s : rightSelected){ rightValues.remove(s); leftValues.add(s); } return null; } public List<SelectOption> getunSelectedValues(){ List<SelectOption> options = new List<SelectOption>(); List<string> tempList = new List<String>(); tempList.addAll(leftValues); tempList.sort(); for(string s : tempList) options.add(new SelectOption(s,s)); return options; } public List<SelectOption> getSelectedValues(){ List<SelectOption> options1 = new List<SelectOption>(); List<string> tempList = new List<String>(); tempList.addAll(rightValues); tempList.sort(); for(String s : tempList) options1.add(new SelectOption(s,s)); return options1; } }

 Did this post answers your questions ,If so please mark it solved so that others get benifited.

 

Thanks

asish