function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
peterg012peterg012 

List Controller New Window PDF

Hi Guys,

 

I have the following visualforce page

 

<apex:page standardController="Production_Request__c" recordSetVar="requests" extensions="productionRequestPrinter" showHeader="false" id="prprinter">
	<apex:form >
		<apex:pageBlock title="Selected Production Requests" id="muselectedlist">
			<apex:pageBlockTable value="{!selected}" var="opp" id="mutab">
		                <apex:column value="{!opp.name}" id="oppname"/>
		    </apex:pageBlockTable>
		    <apex:pageBlockButtons location="top" id="mubut">
		    	<apex:commandButton action="{!doPDF}" value="Print" id="butprint"/>
		    </apex:pageBlockButtons>
		</apex:pageBlock>
	</apex:form>
</apex:page>

 And the following class extension at the moment

 

public with sharing class productionRequestPrinter {
	
	public ApexPages.StandardSetController setCon;
	public PageReference pageRef = ApexPages.currentPage();

    public productionRequestPrinter(ApexPages.StandardSetController controller) {
        setCon = controller;
    }
    
    public PageReference doPDF() {
    	return pageRef;
    }
}

 The above lets a user select records in a list view then is sent to the above VF page to "mass" handle the selected records from the view.    As you can see is that I have a "commandButton" on the pageBlock.  This button should open a new window and generator a PDF document based on the list of records. 

 

I just cannot understand how to do this, because opening a new window is easy, but how do I "pass" the records in context to the second window that would render the PDF?

 

Any advise would be appreciated.

 

Thanks

Peter

ShaTShaT

Hi ,

 

You just need to create the another visual force page with same controller and render it as pdf.

 

call that page in your doPDF mehod

eg-

pagerefrencre p = new pagerefrence(' ' +/apex/pdfpage);

 

Thanks

Shailu

peterg012peterg012

Hi,

 

Thanks for the reply.   I want the "PDF" to be generated in a new window without moving from the current page.  E.g.

 

Landing Page -> Click "Print Button" -> Opens a Window with page that generates PDF.    the user is still on the "orignal" page at this point.

 

Thanks

Peter

vishal@forcevishal@force

Hi,

 

I am not sure if this might be a good solution but you can surely give it a try.

 

On click of the command button, call a pagereference action from your controller,  in the action method give the pagereference to the same page with a parameter like "pdf=true".

In your constructor, use a variable which checks for this parameter and if it is present, you can dynamically render your page as pdf with

 

<apex:page renderAs="{!someVariable}"..>

 

In your controller,

 

Constructor()

{

    if(ApexPages.currentPage().getParameters().containsKey('pdf'))

          someVariable = 'pdf';

}

ShaTShaT

Hi ,

 

You need to write a function in javascript to call that page

eg- 

function DisplayPopup() {
testwindow= window.open ('/apex/pdfpage','width=800,height=600');
testwindow.moveTo(0,0);
testwindow.opener = window;
}

 

 

Thanks

Shailu

peterg012peterg012

Hi,

 

@Vishal Let me play around with this idea.  I might be able to get something to work..

 

Thanks

Peter

peterg012peterg012

Hi,

 

@Shailu - How would the "popup page" be linked to the data?

 

Thanks

Peter

ShaTShaT

Hi ,

 

As  I had already mentioned that use the same controller which you are using on the other page and render it as PDF.

 

Same data will be populated.

 

Thanks

Shailu

 

peterg012peterg012

Hi,

 

@Shailu - I have updated my VF page to the following now

 

<apex:page standardController="Production_Request__c" recordSetVar="requests" extensions="productionRequestPrinter" showHeader="false" id="prprinter">
	
	<script>
		function test() {
			testwindow= window.open ('/apex/productionRequestPDFGenerator','width=800,height=600');
			testwindow.moveTo(0,0);
			testwindow.opener = window;
		}
	</script>

	<apex:form >
		<apex:pageBlock title="Selected Production Requests" id="muselectedlist">
			<apex:pageBlockTable value="{!selected}" var="opp" id="mutab">
		                <apex:column value="{!opp.name}" id="oppname"/>
		                <apex:column value="{!opp.Account__r.Name}" id="oppacc"/>
		                <apex:column value="{!opp.Contact__r.Name}" id="oppacc2"/>
		    </apex:pageBlockTable>
		    <apex:pageBlockButtons location="top" id="mubut">
		    	<apex:commandButton onclick="test();" value="Print Production Requests" id="butprint"/>
		    	<apex:commandButton onclick="test();" value="Mark As Completed" id="butprint2"/>
		    </apex:pageBlockButtons>
		</apex:pageBlock>
	</apex:form>
</apex:page>

 

Then created a "test" second VF page for the popup location called (productionRequestPDFGenerator).   The second page contains this

 

<apex:page standardController="Production_Request__c" recordSetVar="requests" extensions="productionRequestPrinter" showHeader="false" id="prpdf">
	<apex:form >
		<apex:pageBlock title="Selected Production Requests" id="muselectedlist">
			<apex:pageBlockTable value="{!selected}" var="recs" id="mutab">
		                <apex:column value="{!recs.name}" id="recname"/>
		    </apex:pageBlockTable>
		</apex:pageBlock>
	</apex:form>
</apex:page>

 

However the "selected" var on the PageBlockTable does not get the records from the first page.   And it is using the same controller and extension?

 

Thanks

Peter

 

ShaTShaT

Hi , 

 

Are You bindig the selected records in the list in your controller side.  if no 

Than you need to create a list of allselected records in your contoller and display them on the pdf page

 

Thanks

shailu

peterg012peterg012

Hi,

 

Not really, so I have the "extension" class to this now.

 

public with sharing class productionRequestPrinter {
	
	public ApexPages.StandardSetController setCon;
	public PageReference pageRef = ApexPages.currentPage();
	public List<Production_Request__c> records;

    public productionRequestPrinter(ApexPages.StandardSetController controller) {
        setCon = controller;
        setProductionRequestRecords();
    }
    
    public PageReference doPDF() {
    	return pageRef;
    }
    
    public void setProductionRequestRecords() {
    	records = setCon.getRecords();
    }
    
    public List<Production_Request__c> getProductionRequestRecords() {
    	return records;
    }
}

 

Then on the second page / popup ammended to this

 

<apex:page standardController="Production_Request__c" recordSetVar="requests" extensions="productionRequestPrinter" showHeader="false" id="prpdf">
	<apex:form >
		<apex:pageBlock title="Selected Production Requests" id="muselectedlist">
			<apex:pageBlockTable value="{!ProductionRequestRecords}" var="recs" id="mutab">
		                <apex:column value="{!recs.name}" id="recname"/>
		    </apex:pageBlockTable>
		</apex:pageBlock>
	</apex:form>
</apex:page>

 

Now the pop windows displays the following error:

 

System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Production_Request__c.Name 

 

Am I binding and calling it correctly?

 

Thanks

Peter Guest

 

 

ShaTShaT

hi,

 

try this.. 

 

public with sharing class productionRequestPrinter {
	production_Request pr;
	public production_Request__c pro  {get;set;}
	

    public productionRequestPrinter(ApexPages.StandardSetController controller) {
       pr= (Production_Request__c)controller.getRecord();
        setProductionRequestRecords();
    }
    
    public PageReference doPDF() {
    	return pageRef;
    }
    
    public void setProductionRequestRecords() {
    	pro=[select id, name from production_Request__c where id=:pr.id];
    }
    
    public Production_Request__c getProductionRequestRecords() {
    	return pro;
    }
peterg012peterg012

Hi,

 

Thanks, but I am using the "StandardSetController" which is a List Controller, not a single record.   Maybe I am just not understanding, but it looks like your code is for a single record.

 

Thanks

Peter Giest

ShaTShaT

Hi ,

 

Yes its only for single record ,i just gave you the example to show .

 

Please go through this link it will help you 

 

http://www.salesforce.com/us/developer/docs/pages/Content/apex_pages_standardsetcontroller.htm

 

Thanks

Shailu

peterg012peterg012

Hi,

 

I ended up going with 2 visualforce pages. The first uses a commandLink that opens a second page with the list of ID's on the URL, then I run a second query to get the records.

 

Thanks

Peter