You need to sign in to do that
Don't have an account?
Vegaln1
Can I call another VF page from a VF page ?
I have a VF page ( VF page1) that is using a extention Controller to display case history. I have another VF page ( VF page2 ) that will render a printable version of the Case history. I would like to add a command button ( <apex:commandButton) to allow VF page1 to call VF Page2. Is this possible or is there a better way to acomplish this?
Regards,
Sorry, just realised that the first page should, of course, reference a standardController, not a controller...
i.e.
<apex:page standardController="Case" extensions="MyExtension" >
Regards,
Ian Randall
All Answers
Bind your button to a method that returns the PageReference for your second page...
e.g.
<apex:form> <apex:commandButton action="{!NavigateToPrintablePage}" value="Printable Page" /> </apex:form>
then in the controller for VF1,
public PageReference NavigateToPrintablePage() { PageReference pageRef = new PageReference('/apex/vf2'); return pageRef; }
Of course, you can use parameters to pass the Id of the Case to be rendered in your second page...
Hope this helps :)
IanR: Thank you for the suggestion.
Regards,
Ian... Question please.... in your example how would I pass the case Id?
Thanks.
OK,
So I'm assuming you are passing an instance of the ApexPages.StandardController object in your extension constructor - you need to set your Controller to be 'Case' in your first Page
<apex:page controller="Case" extensions="MyExtension" > </apex:page>
then in your extension class:
class MyExtension { private Case thisCase; public MyExtension(ApexPages.StandardController stdController) { thisCase = (Case)stdController.getRecord(); } public PageReference NavigateToPrintablePage() { PageReference pageRef = new PageReference('/apex/vf2'); pageRef.getParemeters().put('caseId', thisCase.Id); return pageRef; } }
so you have put a parameter called 'caseId' into the page reference.
Then in the controller for your second page, you can use ApexPages.currentPage().getParameters().get('caseId') to retrieve the Case Id, which you can use to query the database and build your printable view,
HTH :)
Ian
Sorry, just realised that the first page should, of course, reference a standardController, not a controller...
i.e.
<apex:page standardController="Case" extensions="MyExtension" >
Regards,
Ian Randall
Thanks Ian.... Got it now.
Regards,