2

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>
    

2
  • 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 Dec 29, 2012 at 3:35
  • I've run into this issue severaltimes... However, this is the only place I can find anyone documenting it... Any luck on how to handle this?
    – NSjonas
    May 24, 2016 at 9:02

1 Answer 1

2

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;   
    }
   }  
5
  • Have you tested this? It behaves no different from my code. The URL still changes after the second redirect.
    – Jan Julian
    Jan 1, 2013 at 2:11
  • I believe setRedirect defaults to FALSE, so I wouldn't anticipate any changes. Jan 1, 2013 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. Jan 1, 2013 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
    – Jan Julian
    Jan 2, 2013 at 18:51
  • I have the same issue. Setting redirect does nothing
    – NSjonas
    May 24, 2016 at 8:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .