You need to sign in to do that
Don't have an account?
Is it possible to redirect from a controller?
I have a page controlled by a controller that need to check if a case exists, and if it does, redirect. I'm calling:
redirectPage = new PageReference('http://mypagehere.com');
from a constructor, but it does nothing unless I action it with a visualforce action. I don't really want to do this. What I want to have happen is for anyone that comes to the page and has a parameter that indicates a redirect to simply redirect. A la:
1. User tries to go to page with "http://myorg.com/mpage?case=1
2. Controller says "If case=1, redirect" in the constructor.
Is there no way to do this?
You will have to do an action.
Try something like this
<apex:page controller="test" action="{!test2}">
<!-- Begin Default Content REMOVE THIS -->
<h1>Congratulations</h1>
This is your new Page: test3
<!-- End Default Content REMOVE THIS -->
</apex:page>
public with sharing class test {
public PageReference test2() {
integer x = 0;
if(x == 1)
{
PageReference pageRef = new PageReference('http://www.google.com');
return pageRef;
}
else
{
return null;
}
}
}
All Answers
public class controller {
public controller() {
// case query here
// if statement asking if case was found
{
redirect here if true
}
}
}
Ya - that's what I described trying to do. It does not work. Here is the a code sample.
You will have to do an action.
Try something like this
<apex:page controller="test" action="{!test2}">
<!-- Begin Default Content REMOVE THIS -->
<h1>Congratulations</h1>
This is your new Page: test3
<!-- End Default Content REMOVE THIS -->
</apex:page>
public with sharing class test {
public PageReference test2() {
integer x = 0;
if(x == 1)
{
PageReference pageRef = new PageReference('http://www.google.com');
return pageRef;
}
else
{
return null;
}
}
}