Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have a very simple controller and 3 visualforce pages below which form a 3-page wizard.

The wizard begins at wizard.page with an id parameter so the URL takes the following form /apex/wizard?id=XXX..XXX.

I'd like the URL to remain the same across all 3 pages, however once I reach wizard_step3.page, the URL suddenly changes to /apex/wizard_step2. The URL seems to change to that of the previous VF page.

Everything else works as desired - ie, the view state is maintained. But how can I change this URL behavior?

mycontroller.cls

public with sharing class mycontroller {
    public mycontroller() {}

    public PageReference gotoStep1() {  return Page.wizard; }
    public PageReference gotoStep2() {  return Page.wizard_step2;   }
    public PageReference gotoStep3() {  return Page.wizard_step3;   }
}

wizard.page

  • URL begins with /apex/wizard?id=XXX...XXX
  • Clicking Next: /apex/wizard?id=XXX...XXX

            <apex:pageblockbuttons >
                <apex:commandButton action="{!gotoStep2}" value="Next"/>
            </apex:pageblockbuttons>
    
        </apex:pageblock>
    </apex:form>
    

wizard_step2.page

  • Clicking Next or Previous changes the URL to /apex/wizard_step2

            <apex:pageblockbuttons >
                <apex:commandButton action="{!gotoStep1}" value="Previous"/>
                <apex:commandButton action="{!gotoStep3}" value="Next"/>
            </apex:pageblockbuttons>
    
        </apex:pageblock>
    </apex:form>
    

wizard_step3.page

  • Clicking Previous changes the URL to /apex/wizard_page3

            <apex:pageblockbuttons >
                <apex:commandButton action="{!gotoStep2}" value="Previous"/>
            </apex:pageblockbuttons>
    
        </apex:pageblock>
    </apex:form>
    

share|improve this question
    
One way i would see this can be achieved is have a single page and maintain a boolean in class and keep an output panel for each section and Onclick set the boolean and then render the Panels appropriately.This way URL would remain same –  Mohith Shrivastava Dec 29 '12 at 3:35

1 Answer 1

I think you should use setRedirect(false) function if you don't want to change URL.

If redirect is set to false and the pages share the same set of controllers and extensions, a server-side redirect will take place. In that case The URL won't change.

So i think you should do like this -

    public with sharing class mycontroller {
    public mycontroller() {}

    public PageReference gotoStep1() {  
    PageReference pageRef = new PageReference('partial wizard URL');
    pageRef.setRedirect(false); 
    return pageRef;
    }

    public PageReference gotoStep2() {
    PageReference pageRef = new PageReference('partial wizard_step2 URL');
    pageRef.setRedirect(false); 
    return pageRef;   
   }

    public PageReference gotoStep3() {
    PageReference pageRef = new PageReference('partial wizard_step3 URL');
    pageRef.setRedirect(false); 
    return pageRef;   
    }
   }  
share|improve this answer
    
Have you tested this? It behaves no different from my code. The URL still changes after the second redirect. –  jmrjulian Jan 1 '13 at 2:11
    
I believe setRedirect defaults to FALSE, so I wouldn't anticipate any changes. –  Jeremy Nottingham Jan 1 '13 at 2:53
    
@jmrjulian i tried this first before writing it on stackExchange and it is working. If redirect is set to false and the pages share the same set of controllers and extensions, then only URL would not change. please check your extension and controller specified in <apex:page> tag on all three pages, it must be identical on all three page only then it would work. –  Pramod Kumar Jan 1 '13 at 3:19
    
@PramodKumar The controllers and extensions in the <apex:page> tags are all the same: <apex:page controller="mycontroller">.... It's a bit odd, however, that in my visualforce snippet above, the opening tags for page and form are not being displayed by stackexchange –  jmrjulian Jan 2 '13 at 18:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.