1

I have a multiselect picklist and pageblock table in a visualforce page i want to send the selected multiselect picklist value and modified page block table value to the next visualforce page

This is my vf page code

<apex:pageBlockSection title="Filter based on profiles" collapsible="true" >
     <apex:selectList style="margin-left: 60%;width:150%"  value="{!multival}" size="10" multiselect="true" >
          <apex:selectOptions value="{!Name}"></apex:selectOptions>
     </apex:selectList> 
</apex:pageBlockSection>
<apex:commandButton style="margin-left: 30%;width:5%" value="Next" action="{!redirect}"/> 

This is my first controller code

public String multival {get;set;}
public pagereference redirect(){ 
      PageReference redirect = new PageReference('/apex/nextPage?att='+multival);
      redirect.setRedirect(true);
      return redirect;      

}

This is my second controller code

public class selectedList {
    public String multival {get;set;}
    public selectedList (){
         multival = ApexPages.currentPage().getParameters().get('att');
    }
}

How do i pass the selected multiselect picklist value to my nextpage?

3
  • Is that controller same for both pages? Commented Feb 4, 2019 at 11:24
  • No. controller is different and i have added both the controller code
    – SKH
    Commented Feb 4, 2019 at 11:43
  • 1
    @SKH What's the issue you are facing? Where are you stuck with? Did you get any error?
    – Reshma
    Commented Feb 4, 2019 at 11:58

1 Answer 1

0

Your approach will work. You will get selected values in first vf page in multival variable in controller of nextpage. If you debug multival in selectedList controller, output will look like:

DEBUG| [1, 4]

You need to extract values from this string as:

multival = ApexPages.currentPage().getParameters().get('att');
System.debug(multival);   //[1, 4]
String extractedVal = multival.remove('[').remove(']').deleteWhitespace();
System.debug(extractedVal);   //1,4

If you need values as a list, use:

List<String> extractedVals = extractedVal.split(',');
System.debug(extractedVals);   //(1, 4)
2
  • Yes my approach is working. Is it possible to show the selected values in a dropdown ?
    – SKH
    Commented Feb 5, 2019 at 3:34
  • You can. Add the values you get to a List<SelectOption> as you did for first vf page.
    – Reshma
    Commented Feb 5, 2019 at 5:43

You must log in to answer this question.

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