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

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:selectList>
            </apex:pageblockSectionItem>           
        </apex:pageblockSection>
        <apex:pageBlockButtons >
            <apex:commandButton value=”Pass this” action=”{!pass}”/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
</apex:form>   
</apex:page>



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



Second Page and its Controller:

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



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



Output:



Leave a Reply