2

I have 2 <apex:selectList>. The values of 1 selectList (called Available) are populated from Query. When user selects values from this multi-select selectList, I want to show them immediately in another selectList (called Chosen) just beside it. I'm using actionSupport for this but doesn't seem to work.

Here are the 2 selectLists. On "onclick" event, I'm calling a controller method to put the tasksSelected into TasksChosen

<apex:repeat value="{!MapDep}" var="deptKey">
    <apex:selectList id="Available" value="{!tasksSelected}" multiselect="true" >   
      <apex:actionSupport event="onclick" action="{!AddSelectedTasks}" rerender="chosen"/>
      <apex:selectOptions value="{!MapDep[deptKey]}"/>
    </apex:selectList>         

    <apex:selectList id="chosen" value="{!tasksSelectedByUser}" multiselect="true">
        <apex:selectOptions value="{!TasksChosen}" />
    </apex:selectList> 
</apex:repeat>

But the tasksSelected values from the 1st selectList is null!!

    public void AddSelectedTasks(){     
        System.debug('on click------>'+tasksSelected);
        for(String t:tasksSelected){
            TasksChosenList.add(new SelectOption(t, t));
        }       
    }

    public List<SelectOption> TasksChosenList = new List<SelectOption>();

    public List<SelectOption> getTasksChosen(){     
        return TasksChosenList;
    }

Above is the Add SelectedTasks Method, the debug that I added is giving null. How do I solve this? Any hints?

Note: The two selectLists are inside an <apex:repeat>!

  • Try to change event="onChange" – Peeyush Sep 20 '16 at 6:10
  • hmm I tried, no change! ;) – sfdcFanBoy Sep 20 '16 at 6:16
  • FYI,The two selectLists are inside an <apex:repeat>. Does that hint anything – sfdcFanBoy Sep 20 '16 at 6:18
  • 1
    BTW, your variable names are different. In your AddSelectedTasks you are adding the SelectOption to TasksChosenList, but in your apex:selectList you are using the TaskChosen field -> <apex:selectOptions value="{!TasksChosen}" /> – smukov Sep 20 '16 at 6:22
  • 1
    Best if you add to your question the declaration and getter/setter for tasksSelected as that is ending up null. – Keith C Sep 20 '16 at 7:35
1

Figured out, the setter for TasksSelectedByUser was wrong, my bad! Thanks @Keith C

public void setTasksSelectedByUser(String[] TasksSelectedByUser){
    this.TasksSelectedByUser = TasksSelectedByUser;
}

Thanks All, for the comments!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.