Reputation: 11330
I am having button on VF page for print of the VF page. This page is a search result, so for printing i am generating a very similar page except that it is going to be rendered as pdf. So i want to pass the search criteria entered in the current Vf page to printVF page.
How do i pass variables from one VF page to another
Upvotes: 1
Views: 3391
Reputation: 8255
You can just make the button call an action returning a page reference to the new page:
<!-- in page -->
<apex:commandButton action="{!PrintPage}" value="Print"/>
And then in your controller you can create the page reference and add any parameters you need to:
// in controller
public Pagereference PrintPage()
{
Pagereference pr = Page.ThePrintPage;
pr.setRedirect(true);
pr.getParameters().put('searchFilter1', 'someValue');
pr.getParameters().put('searchFilter2', 'someOtherValue');
return pr;
}
Then in the controller for the other page you can just read these parameters and use them in your query:
string strFilter1 = ApexPgaes.currentPage().getParameters().get('searchFilter1');
If the page is very similar, you may just want to switch the renderAs
parameter in the page tag using a bound variable, and have your action just toggle that — you'd probably want to turn off visibility of other page pieces too, but it would save you doing the query again etc. Of course, if you do need two pages you can always simplify things by doing the search logic in a third class which contains all of the common code.
Upvotes: 1