function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Satish Babu 21Satish Babu 21 

Maintain the user selected state while come from one page to other page

Hi Team,

I have a requirement like page1 and page2. in the page1 have one dropdown with values, if user selects one of the value within the dropdown then respective result set will be displayed in the dashboard.in that dashboard one of the column contains the id, after clicking on the id it will redirects to the respective page.
now my requirement is if user want to come back the page1 then user need to clicks on the cancel button then user will get the page1, but last selected dropdown value i need to display.
can anyone please help me on this.

Thanks in advance.

 
Lokesh__PareekLokesh__Pareek
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_System_PageReference_setRedirect.htm


Example :
Vf page - PageRedirectTest
<apex:page controller="sampleCon">
    <apex:form >
        <apex:selectList value="{!country}"  size="1">
            <apex:selectOptions value="{!items}"/>
        </apex:selectList><p/> 

        <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
        <apex:commandButton value="Next" action="{!redirectNext}"/>   
    </apex:form>

    <apex:outputPanel id="out">
        <apex:actionstatus id="status" startText="testing...">
            <apex:facet name="stop">
                <apex:outputPanel >
                    <p>You have selected:</p>
                    <apex:dataList value="{!country}" var="c">{!c}</apex:dataList>
                </apex:outputPanel>
            </apex:facet>
        </apex:actionstatus>
    </apex:outputPanel>
</apex:page>
Another vf page -  RedirectPage with same controller
<apex:page controller="sampleCon">
<apex:form >
  <apex:commandButton value="Cancel" action="{!redirectOne}"/> 
</apex:form>  
</apex:page>

controller
 
public class sampleCon {
        
        public string country{get; set;}  
             
        public PageReference test() {
            return null;
        }
            
        public List<SelectOption> getItems() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('US','US'));
            options.add(new SelectOption('CANADA','Canada'));
            options.add(new SelectOption('MEXICO','Mexico'));
            return options;
        }
           
        
        public PageReference redirectOne() {
            PageReference p1= Page.PageRedirectTest;
            p1.setRedirect(false);  // maintain state
            return p1;
        }
        
        public PageReference redirectNext() {
            PageReference p1= Page.RedirectPage;
            p1.setRedirect(false);  //maintain state
            return p1;
        }
    }


1) Go to PageRedirectTest

2) Select value from dropdown and click next 

3) Click Canel

dropdown with previous value selected on first page.