Can 2 Vf pages use the same controller and share the data

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.


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();
    }
}

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