Using "action" attribute of Apex:page tag, we can call a page reference method that will return the new page reference or redirect to the new page.
Example:
<apex:page controller="TestController" action="{!checkAndRedirect}"...></apex:page>
Controller:
Public Class TestController{
public PageReference checkAndRedirect()
{
// do checks
//return new pagereference('/apex/testVisualForcePageName'); //return a new PageReference
// or
//return null to go back to the current page
}
}
Note: We cannot return page reference from the constructor.
Example:
<apex:page controller="TestController" action="{!checkAndRedirect}"...></apex:page>
Controller:
Public Class TestController{
public PageReference checkAndRedirect()
{
// do checks
//return new pagereference('/apex/testVisualForcePageName'); //return a new PageReference
// or
//return null to go back to the current page
}
}
Note: We cannot return page reference from the constructor.
No comments:
Post a Comment