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
andersalandersal 

Can't move to next page in wizard

Hi!

 

I am trying to create a wizard. I have copied the functionality in the tutorial in the VF Dev guide. My problem is that I can't navigate to the next page. I am only reloading the same page when I push the next button. Here is my code:

 

The controller:

 

public with sharing class newTOPPController {
    


   // These four class variables maintain the state of the wizard.  
    
   // When users enter data into the wizard, their input is stored  
    
   // in these variables.  
   String[] selectedName = new String[]{};
   Account account;
   Opportunity opportunity;
   OpportunityContactRole role;
   TOPP__c topp;
   Integer ant = -1;
   


   // The next four methods return one of each of the four class  
    
   // variables. If this is the first time the method is called,  
    
   // it creates an empty record for the variable.  
 
  public String[] getName() {
    return selectedName;
  }

  public void setName(String[] nameAccount) {
    this.selectedName = nameAccount;
  }

   public Integer getAntall()
   {
    return ant;
   }
   public void setAntall(Integer a)
   {
    this.ant = a;
   }
   public Account getAccount() {
      if(account == null) account = new Account();
      return account;
   }
   public void setAccount(Account acc)
   {
    account = acc;
   }
   public TOPP__c getTOPP() {
      if(topp == null) topp = new TOPP__c();
      return topp;
   }

   public Opportunity getOpportunity() {
      if(opportunity == null) opportunity = new Opportunity();
      return opportunity;
   }

   public OpportunityContactRole getRole() {
      if(role == null) role = new OpportunityContactRole();
      return role;
   }

   public List<SelectOption> getItems() {
    List<SelectOption> op = new List<SelectOption>();
    for(Account a : [SELECT Id, Name FROM Account]) op.add(new SelectOption(a.Id, a.Name));
    return op;
  }

   // The next three methods are used to control navigation through  
    
   // the wizard. Each returns a reference to one of the three pages  
    
   // in the wizard.  
    
   public PageReference step1() {
      return Page.TOPPCreator;
   }

   public PageReference step2() {
    return Page.TOPPIncomeExpenses;
 
   }

   public PageReference step3() {
      return Page.TOPPIncomeSecure;
   }
    public PageReference step4() {
      return Page.TOPPWealthDebt;
   }

   public PageReference step5() {
      return Page.TOPPSummary;
   }

   public PageReference step6() {
      return Page.TOPPCustomerAgreement;
   }


   
    
   public PageReference save() {

      
    

      return null;
   }
    

}

 

 

//FIRST VF PAGE

 

<apex:page controller="newTOPPController"  tabStyle="TOPP__c">
   <apex:sectionHeader title="Ny TOPP Gjennomgang"
                      subtitle="Steg 1 av 6"/>
<apex:form >
<apex:pageBlock title="Customer Information">

      <!-- This facet tag defines the "Next" button that appears
           in the footer of the pageBlock. It calls the step2()
           controller method, which returns a pageReference to
           the next step of the wizard. -->  
    
       <apex:pageBlockButtons location="top">
        <apex:commandButton action="{!step2}" value="Next"
                            styleClass="btn"/>
      </apex:pageBlockButtons>
      </apex:pageBlock>

    <apex:pageBlock title="Velge kunde">
     <apex:selectList value="{!name}" size="1" required="true">

      <apex:selectOptions value="{!items}"/>
     </apex:selectList>
      
                  
       

    </apex:pageBlock>
</apex:form>

</apex:page>

 

//SECOND VF PAGE

 

<apex:page controller="newTOPPController"  tabStyle="TOPP__c">
   <apex:sectionHeader title="Ny TOPP Gjennomgang"
                      subtitle="Steg 2 av 6"/>
<apex:form >
<apex:pageBlock title="Customer Information">

      <!-- This facet tag defines the "Next" button that appears
           in the footer of the pageBlock. It calls the step2()
           controller method, which returns a pageReference to
           the next step of the wizard. -->  
    
       <apex:pageBlockButtons location="top">
        <apex:commandButton action="{!step3}" value="Next"
                            styleClass="btn"/>
      </apex:pageBlockButtons>
      </apex:pageBlock>

    <apex:pageBlock title="Velge kunde">
     <apex:selectList value="{!name}" size="1" required="true">

      <apex:selectOptions value="{!items}"/>
     </apex:selectList>
      
                  
       

    </apex:pageBlock>
</apex:form>

</apex:page>

 

I someone can help me here I would preciate that very much!!

SargeSarge

Hi Andersal,

 

   I think in first VF page you have a selectList which is required. You need to input some value there to go to next page. Basically, the page is throwing an error when you dont have any value in selectList tag and you can find out the error by placing a simple <apex:pageMessages/> tag before section header tag in First VF page.

andersalandersal

Tnx! That worked, now my problem is that I can't get the value from the selection made in the first VF page and show it in the second. I have been studying many examples, but I can't get it work in my code. Following is my code now:

 

Controller:

 

public with sharing class newTOPPController {
   


   // These four class variables maintain the state of the wizard. 
   
   // When users enter data into the wizard, their input is stored 
   
   // in these variables. 
  public String name;
  public Account acc;
  public Opportunity opportunity;
  public OpportunityContactRole role;
  public TOPP__c topp;
  public Integer ant = -1;
  public String cName = System.currentPageReference().getParameters().get('choosenName');//Try to fetch the selected value


public String getCName() //Return the fetched value
{
return cName;
}
   // The next four methods return one of each of the four class 
   
   // variables. If this is the first time the method is called, 
   
   // it creates an empty record for the variable. 
 
  public String getName() {
    return name;
  }

  public void setName(String n) {
    this.name = n;
  }

   public Integer getAntall()
   {
    return ant;
   }
   public void setAntall(Integer a)
   {
    this.ant = a;
   }
   public Account getAccount() {
      if(acc == null) acc = new Account();
      return acc;
   }
   public void setAccount(Account a)
   {
    acc = a;
   }
   public TOPP__c getTOPP() {
      if(topp == null) topp = new TOPP__c();
      return topp;
   }

   public Opportunity getOpportunity() {
      if(opportunity == null) opportunity = new Opportunity();
      return opportunity;
   }

   public OpportunityContactRole getRole() {
      if(role == null) role = new OpportunityContactRole();
      return role;
   }

   public List<SelectOption> getItems() {
    List<SelectOption> op = new List<SelectOption>();
    for(Account a : [SELECT Id, Name FROM Account]) op.add(new SelectOption(a.Id, a.Name));
    return op;
  }

   // The next three methods are used to control navigation through 
   
   // the wizard. Each returns a reference to one of the three pages 
   
   // in the wizard. 
   
   public PageReference step1() {
      return Page.TOPPCreator;
   }

   public PageReference step2() {
    return Page.TOPPIncomeExpenses;
  
 
   }

   public PageReference step3() {
      return Page.TOPPIncomeSecure;
   }
    public PageReference step4() {
      return Page.TOPPWealthDebt;
   }

   public PageReference step5() {
      return Page.TOPPSummary;
   }

   public PageReference step6() {
      return Page.TOPPCustomerAgreement;
   }


   // This method performs the final save for all objects  

   public PageReference save() {

    //I haven't anything here yet...

      return null;
   }
   

}

 

 

//CODE FOR VF 1

 

<apex:page controller="newTOPPController"  tabStyle="TOPP__c">
   <apex:sectionHeader title="Ny TOPP Gjennomgang"
                      subtitle="Steg 1 av 6"/>
<apex:form >
<apex:pageBlock title="Customer Information">

      <!-- This facet tag defines the "Next" button that appears
           in the footer of the pageBlock. It calls the step2()
           controller method, which returns a pageReference to
           the next step of the wizard. --> 
   
       <apex:pageBlockButtons location="top">
        <apex:commandButton action="{!step2}" value="Next"
                            styleClass="btn">
            <apex:param name="choosenName" value="{!name}">
            </apex:param>               
        </apex:commandButton>
                           
      </apex:pageBlockButtons>
      </apex:pageBlock>

    <apex:pageBlock title="Velge kunde">
     <apex:outputLabel >Kundenavn</apex:outputLabel>
      <apex:selectList value="{!name}" size="1" id="name">
        <apex:selectOptions value="{!items}"/>
      </apex:selectList>
     
                 
      
<apex:pageMessages />
    </apex:pageBlock>
</apex:form>

</apex:page>

 

 

//CODE FOR VF2

 

<apex:page controller="newTOPPController"  tabStyle="TOPP__c">
   <apex:sectionHeader title="Ny TOPP Gjennomgang"
                      subtitle="Steg 1 av 6"/>
<apex:form >
<apex:pageBlock title="Customer Information">

      <!-- This facet tag defines the "Next" button that appears
           in the footer of the pageBlock. It calls the step2()
           controller method, which returns a pageReference to
           the next step of the wizard. --> 
   
       <apex:pageBlockButtons location="top">
        <apex:commandButton action="{!step2}" value="Next"
                            styleClass="btn">
            <apex:param name="choosenName" value="{!name}">
            </apex:param>               
        </apex:commandButton>
                           
      </apex:pageBlockButtons>
      </apex:pageBlock>

    <apex:pageBlock title="Velge kunde">
     <apex:outputLabel >Kundenavn</apex:outputLabel>
      <apex:selectList value="{!name}" size="1" id="name">
        <apex:actionSupport event="onchange" rerender="name"/>
         <apex:selectOptions value="{!items}"/>
      </apex:selectList>
     
                 
      
<apex:pageMessages />
    </apex:pageBlock>
</apex:form>

</apex:page>

SargeSarge

Hi Andersal,

 

   I would suggest you to use standard inline getter and setter to all of your public variables like the following one

 

  public Account acc {get; set;}

 

 

    The apex will generate standard getter and setter for you and you can avoid typing getter and setters that are actually standard.

Lets come to your problem now.

  So when you click this button "Next" all the setters will be executed first including the value in the selection. So when  the system actually executes the action method for the commandButton, all the setters are already executed. so mark this method as the carrier of the selection value to next page.

 

  And an important point when coding vf wizards. At the end of the method called by next button, instead of using

 

return Page.TOPPCreator;

 

use

 

PageReference pNext = new PageReference("/apex/TOPPCreator");

pNext.setRedirect(false);

return pNext;

 

by invoking setRedirect(false); method of Pagereference instance you are actually preserving the values selected in first page inside the controller and hence you can take it to next page.