Wednesday, 21 September 2011

Tuesday, 20 September 2011

How to display multiple visual force pages using controller?

Hi,

I have posted this question in discussion boars.I didnt get any response.Please help me to find a solution for this.

Im using 2 vf page and a controller.
One VF is used to select multiple values from the list view.When i select multiple values the values should display in visual force page.I have created a button there named Print.When i click that button i should get the print of (Second VF) all the pages.
Second VF is the page which is to be printed.
Im using controller to print the Second VF page.My issue is In controller inside for loop all the page are printing.Outside the loop it will return only one page.

First VF page

<apex:page standardcontroller="Payment_Schedule__c"  recordsetVar="pay1" 
extensions="MassPrintSimpleController" showHeader="true">

<apex:form >
<apex:pageBlock mode="edit">
<apex:pageBlockSection >
<apex:pageBlockTable var="a" value="{!selected}">
<apex:column value="{!a.Opportunity__c}"/>
<apex:column value="{!a.Name}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Print"  action="{!print}">
</apex:commandButton>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

Controller:

public  class MassPrintSimpleController {

    public id Oppid; 
    public  ApexPages.StandardSetController cntr;
    private PageReference pr;
    public List<Payment_Schedule__c> pay{ get; set;}
    public Payment_Schedule__c pay1;
    public MassPrintSimpleController(ApexPages.StandardSetController 
controller) {
        system.debug('Controller111111111111');
        cntr = (ApexPages.StandardSetController)controller;
        system.debug('Controller'+cntr);
        pay=cntr.getSelected();
        system.debug('PaymentSchedule111111'+pay);
    }
     
    public PageReference print() {
    
        system.debug('Printttttttttttttttt');
        system.debug('Payment11111111111'+pay.size());
        system.debug('Pay Id: ' + pay[0].id);

        for(Payment_Schedule__c pay1:pay) {  
        system.debug('DemandLeterSize'+pay.size());    
        
             pr =new PageReference('/apex/DemandLetterPrint?id='+pay1.id);
             pr.setRedirect(true);
             System.debug('PrintPDF'+pr);
             System.debug('printing pdf'+pay1); 
                             
              }
              return pr;
              }
              }
 
Anyhelp would be highly appreciated.

Thanks
Speculator