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
bond006bond006 

Two Visual force pages and one controller

Hi,

I have created 2 visualforce pages with one controller. 

First Page:  It has a multiselect picklist which shows a list of string. Once values are selected and a button is clicked then it goes to second page.
Second Page: The First Column is a list of another string that are generated from the code.It shows a table with columns as the list that it got from the First Page. The table values or the data in the table is from a wrapper class.

Fucntion : Once clicked on Save Button then wrapper list will be sent back to method in the controller and it saves.

Problem: The controller is not getting the values from Second Visualforce page. Once we call for the list it is giving old values.The list is controlling the values that are put into it to show on the table. The list is not getting updated with the changes. 
James LoghryJames Loghry
How are you passing the variables from the first to the second page exactly?  If the <apex:page> tag is similar, that is the pages use the same controller and/or extensions, then it should retain the variables across page clicks.  If you're noticing your variables are resetting, then check to see if you have any transient variable declarations or are redirecting using setRedirect(true) on the page reference.  Both of these could cause issues with your use case.

If you're still struggling, then go ahead if you would and post a snippet of your controller and VF pages (using the < > button above) so we can be of better assistance.
padmapadma
Hi can you  share a code for that one please.
Thanks&Regards
 
bond006bond006
Second Page:
<apex:page standardController="MPM__c" extensions="Allocatepages" sidebar="false">
 <apex:form >
        <apex:pageBlock >
           <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!Saves}"/> 
               
                <apex:commandButton value="Cancel" action="{!Cancel}"/>
            
            </apex:pageBlockButtons>
          <apex:pageBlockSection title="Allocate Ec to Video Version" columns="1">
           
         
            <apex:outputPanel >
             <div style="overflow: auto;">  
               <apex:pageBlockTable styleClass="teststyle" id="tables" value="{!EcpieceList}" var="ec2">
                
                   <apex:column style="white-space: nowrap;" width="30px"><apex:facet name="header">MPM:{!mpmNames}</apex:facet>{!ec2.EC_Name__c} <br/> {!ec2.Name}</apex:column>
                   
                   <apex:repeat value="{!TitlesecondList}" var="tit2">
                   <apex:column style="white-space: nowrap;"><apex:facet name="header">{!tit2.Video_Version__c}<br/>{!tit2.Name}</apex:facet>
                        
                        <apex:repeat value="{!displayECT}" var="ect4">
                        
                        <apex:outputPanel rendered="{!AND(ec2.EC_Name__c = ect4.ecname,ect4.VideoVersion = tit2.Video_Version__c)}" >
                          
                          <apex:inputCheckbox value="{!ect4.check}"/></apex:outputPanel>
                        </apex:repeat>
                         
                   </apex:column>
                   </apex:repeat>
                  
                </apex:pageBlockTable>   </div>                  
           </apex:outputPanel>
          </apex:pageBlockSection> 
          
        </apex:pageBlock>
        
       
    </apex:form>
    
</apex:page>

Controller snippet:

public PageReference Saves1(){

      rightList = new List<String>();



      rightList.addAll(rightvalues);



      PageReference Save2= new PageReference('/apex/test_page2');

      Save2.setRedirect(false);

      secondpages();

     

      //displayECT = displayECTss;

      return Save2;

   }

   

  public PageReference Saves(){

       List<EC_Title_Allocation__c> insertECT = new List<EC_Title_Allocation__c>();

       List<EC_Title_Allocation__c> deleteECT = new List<EC_Title_Allocation__c>();

   

       for(ECandTitle dect:displayECT){


         if(dect.ectid == null && dect.check == true){

            EC_Title_Allocation__c ectnew = new EC_Title_Allocation__c ();

            ectnew.EC_Piece__c = dect.ECId;

            ectnew.MPM__c = mpmIds;

            ectnew.Title__c = dect.TitleId;

               

            insertECT.add(ectnew);

         }else if(dect.check == false && dect.ectid != null){

            EC_Title_Allocation__c deletect = new EC_Title_Allocation__c ();

            deletect.EC_Piece__c = dect.ECId;

            deletect.MPM__c = mpmIds;

            deletect.Title__c = dect.TitleId;

            deletect.Id = dect.ectid;



            deleteECT.add(deletect);

         }

       }

       insert insertECT;

       delete deleteECT;

       PageReference Save1= new PageReference('/'+mpmIds);

       return Save1;

   }
public void secondpages(){ 

    //second page

    system.debug('came here----------------------');

    EcNameList = new List<String>();

    TitleList = new List<Title__c>();

    TitlesecondList = new List<Title__c>();

    EcpieceList = new List<EC_Piece__c>();

    displayECT = new List<ECandTitle>();

    

    EcpieceList = [select Name,EC_Name__c,Id,MPM__c from EC_Piece__c where MPM__c=:mpmIds 

order by Name];

    TitleList = [select Name,Id,MPM__c,Video_Version__c from Title__c where MPM__c=:mpmIds];

    Ectitles = [select 

EC_Piece__c,MPM__c,Title__c,EC_Name__c,Video_Version_Number__c,checkedbox__c from 

EC_Title_Allocation__c where MPM__c=:mpmIds];

    

    

    if(rightList!=null && rightList.size()>0){

       

           for(EC_Piece__c ec:EcpieceList){

            

            

               EcNameList.add(ec.EC_Name__c);

           }

           Boolean checkboxes;

  

           for(Title__c tit3:TitleList){

           

               for(string vvsn:rightList){

                  

                   if(vvsn == (tit3.Video_Version__c + '-' + tit3.Name)){

                      TitlesecondList.add(tit3);

                      for(EC_Piece__c ecnme:EcpieceList){

                          checkboxes = false;

                          Id ectid = null;

                          for(EC_Title_Allocation__c ect2:Ectitles){

                                                  

                              if(checkboxes == false){

                                 if((ect2.EC_Name__c == ecnme.EC_Name__c) && (ect2.Video_Version_Number__c 

== tit3.Video_Version__c)){

                                     

                                     checkboxes = true;

                                     ectid = ect2.Id;

                                 }else{

                                    

                                     checkboxes = false;

                                 }

                              }   

                          }

                          
                          displayECT.add(new 

ECandTitle(ecnme.EC_Name__c,tit3.Name,tit3.Video_Version__c,tit3.Id,ecnme.Id,ectid,checkboxes));

                     

                      }

                   }

                }

             }

        }

   }
bond006bond006
@James Loghry
I have not setRedirect to true so that it passes that RightList to the second page. The Second Page is displaying fine but while saving SET  returning the old values not updated values. And I am using the Apex Page tag same in both pages.