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
SkyBlue2007SkyBlue2007 

setRedirect(false) doesn't work !

Hi everyone,

 

I have two visualforce pages whose name are "PageTransition" and "nextPage".

They share the same custome controllear of which is "PT".

I use setRedirect(false) because I want to share several same parameters in transition from "PageTransition" to "nextPage".  

But setRedirect(false) doesn't work !

 

Here is PageTransition.

<apex:page controller="PT" action="{!nextPage}" sidebar="false"> <!-- Begin Default Content REMOVE THIS --> <h1>Congratulations</h1> This is your new Page: PageTransition <!-- End Default Content REMOVE THIS --> </apex:page>

 

Here is nextPage.

<apex:page controller="PT" tabStyle="PageTransition__tab" sidebar="false"> test0 is {!test0}<br/> test1 is {!test1}<br/> test2 is {!test2}<br/> </apex:page>

 

Here is the controller method.

public class PT { public String test0 { get; set; } public String test1 { get; set; } public String test2 { get; set; } public PageReference nextPage() { test0 = 'aaa'; test1 = 'bbb'; test2 = 'ccc'; PageReference np = Page.nextPage; np.setRedirect(false); return np; } }

 

 

Tab name is "PageTransition".

Ankit AroraAnkit Arora

Try something like this :

 

 

public class PT
	{
		public String test0 { get; set; }
		public String test1 { get; set; }
		public String test2 { get; set; }
		public PageReference nextPage()
		{
			test0 = 'aaa';
			test1 = 'bbb';
			test2 = 'ccc';
			//PageReference np = Page.nextPage;
			PageReference np = new PageReference('/apex/nextPage');
			np.setRedirect(false);
			return np;
		}
	}

 

 

Hopefully this will resolve your problem.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

SkyBlue2007SkyBlue2007

Hi Ankit, 

 

Thank you for your prompt reply.

I edited "PT" and tried, but I couldn't resolve my problem.

 

Thanks,

Seiji

bob_buzzardbob_buzzard

Can you clarify what you mean by doesn't work?

 

If redirect is set to false and the pages share the same set of controllers and extensions (which certainly appears to be the case here), a server-side redirect will take place.  The URL won't change if that is what you are expecting?  Or is it the case that your properties aren't showing up correctly in the page?

bob_buzzardbob_buzzard

I've recreated your scenario in my dev org and I see exactly the same as you - it looks like the server side redirect isn't honoured when carried out from a page action.

 

If you can stand the user briefly stopping on your transition page, you can use an actionfunction to forward the user on as soon as the page is rendered like so:

 

 

<apex:page controller="PT" sidebar="false">
  <apex:form > 
     <apex:actionFunction name="forward" action="{!NextPage}"/> 
     <!-- Begin Default Content REMOVE THIS --> 
     <h1>Congratulations</h1> 
     This is your new Page: PageTransition <!-- End Default Content REMOVE THIS -->
   </apex:form>
   <script>
      forward();
   </script> 
</apex:page>

 

And you could also set a have a new page action method that sets a property to stop any content being rendered if the user is going to be sent forward.

 

SkyBlue2007SkyBlue2007

Hi Bob,

 

Thank you for your reply.

I'll use your advice as a reference, but I'd like to think a way of not using javascript.

 

Force.com Apex Code Developer's Guide says,

 

----setRedirect----

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.

 

Force.com Apex Code Developer's Guide is version 21.0 and Spring'11.

 

Thanks,

Seiji

bob_buzzardbob_buzzard

You are correct that the docs indicate it should work.  There's obviously something special about the page action method but as its server side redirecting, we have no visibility of what is actually happening.

Prajapati.LakhanPrajapati.Lakhan

Yes I think so, if you don't stay on the page (with form), viewstate will not be created and you can't get the benefit sharing values b/w two pages.

Saravanan @CreationSaravanan @Creation

Hi Bob,

 

I am using 2 pages with same controller. In the first page i have one button when i click the button i need to redirect to 2 page

so, i used page.setredirect(false).

 

But here i am facing odd issues . If i click the first page button nothing is happening and if i click second time again.

i am facing 'The page you submitted was invalid for your session. Please click Save again to confirm your change'.

 

 

Could you please give me the solution.

 

 

Jorge Esparza 4Jorge Esparza 4
Has anyone found an answer, or an alternative to this issue? I just ran to the same issue trying to share one controller between two .vfp. While I need the controller information to persist between pages, it would not redirect on setRedirect(false). It will only work if I set setRedirect(true). Not even working if I point the setRedirect(false) to a different page.
Jorge Esparza 4Jorge Esparza 4
If anyone in the future runs into this error, this how I solved it on my end. It might be isolated to my issue, but it works.

On the button that calls the function with your PageReference.#visualforcePage#.setRedirect(false), make sure you don't have any rerender options. Apparently the rerender command will keep the state on the first VisualForce page, rather than obeying the redirect command.
 
<apex:commandButton 
  action="{!doSave}" 
  value="Save & Continue" 
  status="loadingStatus" 
  rerender="messages,scripts,main,overlay" <!-- Remove this section--> >

Again this might be a situational basis solution but it worked for me, in case anyone else stumbles with this post again.

Safe trips fellow developers.
Arjun AccentureArjun Accenture
Yes Jorge,, you are right ..if rerender is there it will give first priority to current page only and that is the reason setReDirect(false) was not working here.

but here are some more points to consider when going for to redirect another page from one vf page
1. they should share same controller or extention(depends on from which class, i mean controller or extension yoou are doind redirect).
2. rerender attribute should not be included in way of calling method which is doing redirect.
3. if you are trying to send paramenteres then it should set to false and in that you won't loss view state as well and also it will be a server side call.
4. but if it is just redirct then no need to set false set it true but you will loss view state of current page and also it will be client side call in that case.
5. redirect will occur in any case -- true or false..the only different is, paramenter won't be available in case of true redirect