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
cedgcedg 

redirect with action attribute doesn't work

Hello,

I've a site with a wizard in it. When the user goes to the site, i check in the first page if this user is already came. If so, i load the saved state of his wizard and make a redirect to the correct page of the wizard.

To redirect him, i use the action attribute of the page. 

 

<apex:page sidebar="false" showheader="false" controller="Move_North" cache="false" action="{!ad.loadCafState}">

 ad is an object created in the controller of the page.

 

The function loadCafState is looking like:

pageRef = new PageReference('/apex/HR01_Confirm_And_Send');
pageRef.setRedirect(false);
return pageRef;

 (I don't use /apex/ in my real code, it's just to debug.

 

With the parameter of setRedirect = true, i move correctly to the page, but i lose all values preloaded. Normal if i refer to the documentation.

With setRedirect = false, the page seems not to be redirected, and doesn't display the css anymore ???

 

In the documentation, i find "If set to false, the redirect is a server-side forward that preserves the view state if and only if the target page uses the same controller and contains the proper subset of extensions used by the source page"

 

What is a proper subset of extensions ?

When is executed the method in the action attribute compared to the execution of the controller ?

 

Thanks for your help

Ced

sfdcfoxsfdcfox

The "same controller and proper subset of extensions" means that the "controller" must match on each page, and "proper subset of extensions" means you're allowed to remove extensions, but not add them. So long as you meet these requirements, your page will maintain its state when redirecting.

 

Keep view state:

 

<!-- page 1 -->
<apex:page controller="Wizard_Controller"> ...

<!-- page 2 -->
<apex:page controller="Wizard_Controller"> ...
-----------------------------------------------------------------
<!-- page 1 -->
<apex:page controller="Wizard_Controller" extensions="Wizard_Extension"> ...

<!-- page 2 -->
<apex:page controller="Wizard_Controller" extensions="Wizard_Extension"> ...
-----------------------------------------------------------------
<!-- page 1 -->
<apex:page controller="Wizard_Controller" extensions="Extension1,Extension2"> ...

<!-- page 2 -->
<apex:page controller="Wizard_Controller" extensions="Extension2"> ...

Lose view state:

 

<!-- page 1 -->
<apex:page controller="Wizard_Page1"> ...

<!-- page 2 -->
<apex:page controller="Wizard_Page2"> ...
-----------------------------------------------------------------
<!-- page 1 -->
<apex:page controller="Wizard_Controller"> ...

<!-- page 2 -->
<apex:page controller="Wizard_Controller" extensions="Extension1"> ...

Note that when a view state transfers via an internal (server) redirect, the URL will still reference the origin page, but will be running the new page's code.

cedgcedg

That's what i have 

 

My first page , where the action is called

<apex:page sidebar="false" showheader="false" controller="Move_North" cache="false" action="{!ad.loadCafState}">

And the page (named HR01_Confirm_And_Send ) where the app is redirected is :

<apex:page sidebar="false" showheader="false" controller="Move_North">

 

So the redirect should work, no ?