How to send picklist values from one VF page to another?

Sample codes:

First Page and its Controller:

<apex:page controller="Sample" >
<apex:form >
    <apex:pageBlock >
        <apex:pageblockSection >
            <apex:pageblockSectionItem >Select the value to pass:</apex:pageblockSectionItem>
            <apex:pageblockSectionItem >
                <apex:selectList size="1" value="{!option}" >
                    <apex:selectOption itemValue="red" itemLabel="Red"/>
                    <apex:selectOption itemValue="green" itemLabel="Green"/>
                    <apex:selectOption itemValue="blue" itemLabel="Blue"/>                                       
        <apex:pageBlockButtons >
            <apex:commandButton value="Pass this" action="{!pass}"/>

public class Sample
    public String option {get;set;}
    public pageReference pass()
        PageReference pg = new PageReference('/apex/Sample1?val=' + option);
        return pg;

Second Page and its Controller:

<apex:page controller="Sample1" >
The received value is {!option}

public class Sample1
    public String option {get;set;}
    public Sample1()
        option = ApexPages.currentPage().getParameters().get('val');


No comments:

Post a Comment

Sharing is Caring!!! Share this with your friends!!!

submit to reddit