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?

  • Is that controller same for both pages? – Santanu Boral Feb 4 at 11:24
  • No. controller is different and i have added both the controller code – SKH Feb 4 at 11:43
  • 1
    @SKH What's the issue you are facing? Where are you stuck with? Did you get any error? – Reshma Feb 4 at 11:58
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)
  • Yes my approach is working. Is it possible to show the selected values in a dropdown ? – SKH Feb 5 at 3:34
  • You can. Add the values you get to a List<SelectOption> as you did for first vf page. – Reshma Feb 5 at 5:43

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.