18

Here is a scenario where i have a search page with filters for users to select and display the search results. I also have a button to generate the pdf.

I have a list of account in the controller which displays the search result. I am doing the exact same thing in the page i am generating the pdf except that i am passing the selected parameters into vf page rendered as pdf and requerying it and generating the list.

These work fine.. But now i need to give an ability to remove some search result records and this needs to be generated as pdf.

I was wondering if i can share the data from the search page to VF page if i was using the same controller?

18

Yes, the view state will be shared across Pages, which share a controller, so long as you don't perform a redirect, because this flushes the view state.

If set to true, a redirect is performed through a client side redirect. This type of redirect performs an HTTP GET request, and flushes the view state, which uses POST. 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.

4

Yes you can! I have the same application where the user can search for some data and then export it as pdf file. So i have created two pages with only one controller. The search page use the ApexPages.StandardSetController because of pagination for the search results.

Here is a smal example of the controller:

public with sharing MyController(){

    // The standard set controller to be used at the search page with pagination
    public ApexPages.StandardSetController setController { get; set, }
    // The list will be shown at the search page
    public List<Accounts> acc { get; set; }

    public PageReference search(){
        String myQuery = 'Select Id, Name From Account Where Amount > 10';
        setController = new ApexPages.StandardSetController(Database.getQueryLocator(myQuery));
        // Here defining pagination step size
        setController.setPageSize(10);
        // Fill out the list to be used at the search page
        acc = (List<Account>) setController.getRecords();
            return null;
    }

    public List<Account> getResults(){
        // Important! Setting the page size back to be able to output ALL records for the pdf
        setController.setPageSize(setController.getResultSize());
        return (List<Account>) setController.getRecords();
    }

    public List<Account> getResultsForPdf(){
        // Important! Setting the page size back to be able to output ALL records for the pdf
        setController.setPageSize(setController.getResultSize());
        return (List<Account>) setController.getRecords();
    }
}
2

Note also the Wizard CustomController example in the VF official developer's doc - http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_quick_start_wizard.htm uses multiple pages sharing the same controller with next/previous buttons doing the navigation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.