5

I am experiencing an odd behavior on my visual force pages and i would like to know if others have experienced this. I have a multistep wizard where several visual force pages use one controller. On the very first visual force page say /apex/vf1 there is a command link button which on clicking does some processing on the controller and does a page reference forward to vfpage2. At this point the vfpage2 gets loaded on the browser but the url still says /apex/vf1 on the browser. Now i hit next command link button on vfpage2 which does processing on the controller and does a page reference forward to vfpage3. Now vfpage 3 loads on the browser and the url changes to /apex/vfpage2. So the url on the browser changes one step after the page is loaded and the user clicks a button on it. Can you guys explain why? My assumption is that the url should change on page on load on the browser..

6

I suspect the PageReference objects you are returning have setRedirect as false. This is a server side redirect that preserves the wizard viewstate between post back requests and can only occur with a shared controller.

If setRedirect were true then a client side redirect would result in an HTTP GET request to the subsequent page and the URL would change. You would also lose any view state that had been accumulated.

When you perform subsequent POST requests back on a page it advances to the previous visualforce page as that is where the POST is being sent to.

E.g.

  1. GET request to /apex/vf1
  2. COMMAND button performs a POST to /apex/vf1
    Salesforce responds with the new HTML, still on /apex/vf1. The new content will send a POST request to /apex/vf2
  3. COMMAND button performs a POST to /apex/vf2, Browser URL changes to /apex/vf2.
    Salesforce responds with the new HTML that will send a POST request to /apex/vf3
  4. ...
  • Hi Daniel, Thanks for your reply. In our case we want the view state to be preserved. You are right that we are not setting the redirect to true in this case on the page reference. So just to understand, if we use the same controller, every vf page would post to itself first and just the data would be changed by the view state . Is this right? If you enable view state on the developer console, you would notice that the apex class would be the wrong class and developer would update the wrong class. Is there a fix to that? – buyan kumar Mar 7 '13 at 21:45
  • @buyankumar, Each POST request will go to the correct Visualforce page. As they all share the same Apex controller the view state will be maintained. Try using using something like the network tab in the Chrome developer tools. You should see the request/response pattern. Or look at the HTML source after each command button press. The form action and method should show you what is happening. – Daniel Ballinger Mar 7 '13 at 21:55
  • Yes i viewed through google chrome network tools. Your response answered this question. Thanks a lot for your quick reply. Where are you located? – buyan kumar Mar 7 '13 at 22:03
  • @buyankumar Great. You can mark the answer as correct using a tick mark by the voting buttons. I'm in New Zealand. You can check users details from their profile pages by clicking on their name. – Daniel Ballinger Mar 7 '13 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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