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
orPrevious
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>
Best Answer
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 -