0

Why should selectedsProdAdd (that represents the value for one of the selectList in the page) be null in the LtoR() method?

Controller:

    public without sharing class PackManager {  

    public String selected {get;set;}
    public List<String> selectedsProdAdd {get;set;}
    public List<String> selectedsProdRemove {get;set;}

    public map <Id,String> selectedsProdAddMap {get;set;}
    public map <Id,String> selectedsProdsRemoveMap {get;set;}

    //per renderizzare o meno i bottoni di spostamento a destra o sinistra 
    public Integer dimEsistenti {get;set;}
    public Integer dimDisponibili {get;set;}


    public boolean openEdit {get;set;}
    public List<Pacchetto__c> pacchettoName = [SELECT Name from Pacchetto__c];  
    public List<toninotripWR__Pacchetto_Prodotto__c> existingProdsList {get;set;}
    public List<Product2> availableProdsList {get;set;}
    public Pacchetto__c p {get;set;}

    private ApexPages.StandardController pcontroller1 {get;set;} 


    public PackManager(){

    }

    public PackManager(ApexPages.StandardController controller1) {

        pcontroller1=controller1;   
        this.p = (Pacchetto__c)controller1.getRecord(); 
    }   

    public List<SelectOption> getPKTS () {

        pacchettoName = [SELECT Id,Name from Pacchetto__c]; 
        List<SelectOption> pacchetti = new List<SelectOption>();
        pacchetti.add(new SelectOption('-- None --', '-- None --'));
        for(Pacchetto__c pkt : pacchettoName) {
        pacchetti.add(new SelectOption(pkt.Name,pkt.Name));     
        }       
        selected  = '-- None --';
        openEdit=false;     
        return pacchetti;       
    }

    public List<SelectOption> getExisting () {

        existingProdsList = [SELECT Id,Prodotto__r.Name FROM toninotripWR__Pacchetto_Prodotto__c WHERE Pacchetto__r.Name =: selected];
        List<SelectOption> esistenti = new List<SelectOption>();
        for(toninotripWR__Pacchetto_Prodotto__c existing : existingProdsList) {             
            esistenti.add(new SelectOption(existing.Prodotto__r.Name, existing.Prodotto__r.Name));
        }

        dimEsistenti =  esistenti.size();   
        return esistenti;


    }   

    public List<SelectOption> getAvailable () {

        availableProdsList = [SELECT Id,Name FROM Product2 
                            WHERE Id NOT IN (SELECT Prodotto__c FROM toninotripWR__Pacchetto_Prodotto__c WHERE Pacchetto__r.Name =: selected)];
        List<SelectOption> disponibili = new List<SelectOption>();
        for(Product2 available : availableProdsList) {
            disponibili.add(new SelectOption(available.Name, available.Name));
        }

        dimDisponibili = disponibili.size();
        return disponibili;

    }

    public List<Product2> getDescribeAllProducts(){

        return [SELECT Id,Name, isActive, ProductCode, Family From Product2];           
    }

    public pageReference OpenEdits(){       

        if(selected== '-- None --') {           
            return null;
        }
        openEdit=true;
        return null;

    }   

    public PageReference LtoR () {

        system.debug('@@@@@@@selectedsProdAdd: ' + selectedsProdAdd);

        if(selectedsProdAdd!=null && selectedsProdAdd.size()> 0) {          

            Id rightPack = [SELECT Id FROM Pacchetto__c where Name =: selected].Id; 
                system.debug('rightPack: ' + rightPack);    
            List<toninotripWR__Pacchetto_Prodotto__c> helper = new List<toninotripWR__Pacchetto_Prodotto__c>();
            List<Id> prodIDS = new List<Id>();

            for(Product2 prodotto : [SELECT Id From Product2 where Name IN : selectedsProdAdd]) {

                prodIDS.add(prodotto.Id);
            }       

            for( Id idProdotto : prodIDS) {

                toninotripWR__Pacchetto_Prodotto__c temp = new toninotripWR__Pacchetto_Prodotto__c(Pacchetto__c = rightPack, Prodotto__c = idProdotto);
                helper.add(temp);
            }

            insert helper;
            return null;

        }

        else {

            return null;
        }
    }

    public void RtoL () {



    }


}

Page:

<apex:page standardController="Pacchetto__c" extensions="PackManager" id="thePage">

<style type="text/css">

    .selectListL {margin-right:15px; margin-left:160px}
    .selectListR {margin-left:15px}

</style>
    <apex:form >
        <br/>       
        <apex:image id="LogoPannello" value="{!$Resource.Pannello}"/>       
        <br/>
        <apex:pageMessages />   
        <apex:tabPanel switchType="client">
            <apex:tab label="Info Prodotti">
                <apex:pageBlock title="Descrizione di tutti i prodotti">
                    <apex:pageBlockSection id="tutti" >                 
                        <apex:pageBlockTable value="{!DescribeAllProducts}" var="allprods">
                            <apex:column headerValue="Nome" value="{!allprods.Name}">                               
                            </apex:column>
                            <apex:column headerValue="Attivo" value="{!allprods.isActive}">
                            </apex:column>
                            <apex:column headerValue="Codice" value="{!allprods.ProductCode}">                      
                            </apex:column>      
                            <apex:column headerValue="Famiglia" value="{!allprods.Family}">                         
                            </apex:column>                  
                        </apex:pageBlockTable>
                    </apex:pageBlockSection>    
                </apex:pageBlock>
            </apex:tab> 
            <apex:tab label="Monitora configurazioni">              
                <apex:pageBlock >                   
                    <apex:pageBlockSection >    
                    </apex:pageBlockSection>
                </apex:pageBlock>
            </apex:tab>
            <apex:tab label="Configura un pacchetto" id="tab2"> 
                <apex:outputPanel id="edits">           
                <apex:pageBlock id="editor" title="Scegli un pacchetto o crea un nuovo pacchetto">
                    <apex:pageblockSection>
                        <apex:pageBlockSectionItem > 
                        </apex:pageBlockSectionItem><br/>
                        <apex:pageBlockSectionItem >                
                            <apex:outputLabel value="Scegli un pacchetto:  "/>
                            <apex:outputPanel >
                                <img src="/img/samples/color_red.gif" align="absmiddle" width="3" height="18" />
                                <apex:selectList value="{!selected}" size="1">
                                    <apex:selectOptions value="{!PKTS}"/>
                                </apex:selectList>
                                <apex:commandButton value="Configura" action="{!OpenEdits}" rerender="tabelleProdotti"/>    
                            </apex:outputPanel>
                        </apex:pageBlockSectionItem><br/><br/>
                        <apex:pageBlockSectionItem >
                            <apex:outputLabel value="Crea nuovo inserendo il nome:  "/>
                            <apex:outputPanel >                             
                                <apex:inputField value="{!Pacchetto__c.Name}"/>
                                <apex:commandButton value="Crea" action="{!quicksave}" rerender="edits"/>   
                            </apex:outputPanel>                         
                        </apex:pageBlockSectionItem>                            
                    </apex:pageblockSection>        
                </apex:pageBlock>   
                <apex:outputPanel id="tabelleProdotti">                     
                <apex:pageBlock id="editaScelto" title="Configurazione pacchetto : {!selected}" rendered="{!openEdit}"> <br/><br/>                          

                        <div>                                           
                        <apex:selectList styleClass="selectListL" value="{!selectedsProdAdd}" multiselect="true">
                            <apex:selectOptions value="{!Available}"/>
                        </apex:selectList>                              
                        <apex:commandButton value=">" reRender="editaScelto" action="{!LtoR}"/> 
                        <apex:commandButton value="<" reRender="editaScelto"/>
                        <apex:selectList styleClass="selectListR" value="{!selectedsProdRemove}" multiselect="true">
                            <apex:selectOptions value="{!Existing}"/>
                        </apex:selectList>                      
                        </div>

                </apex:pageBlock>
                </apex:outputPanel>
                </apex:outputPanel>         
            </apex:tab>         
        </apex:tabPanel>
    </apex:form>
</apex:page>
4
  • 1
    The first thing to try is to initialise it to an empty list in the constructor so that the apex:selectList has an existing collection to add values into.
    – Keith C
    Nov 20, 2014 at 16:26
  • I did it. Now, when I select some values and hit the button that calls the method, my list is empty. Any suggestions?
    – user9959
    Nov 20, 2014 at 16:51
  • 1
    If you can't figure out what is wrong, you could take the option of incorporating this metadaddy-sfdc/Visualforce-Multiselect-Picklist component instead.
    – Keith C
    Nov 20, 2014 at 21:55
  • 1
    I am facing the same issue.Were you able to figure this out?
    – Suneel
    May 10, 2016 at 17:20

0

You must log in to answer this question.