You need to sign in to do that
Don't have an account?
Jon Mountjoy_
PDF generation from VF fails if button has rendered attribute
I have a Visualforce page that renders as PDF (depending on an incoming parameter) when a button is pushed.
However, if that button has a "rendered" attribute, then the PDF fails to render for some reason. (I don't want the button rendered if I'm producing a PDF, as I don't want to see it in the PDF). Instead, the page simply refreshes. This seems a little odd - any idea what's up?
Here' s the page:
Here's the controller:
I've blogged about this (sans problem) here.
I know I can solve my problem in a different way (style sheets come to mind), but I'd really like to figure out why, when a button has a rendered='false', it no longer generates a PDF. (I mean, I've already pushed it, and an action is occuring, so whether the button itself is present or not in the result shouldn't matter?)
Thanks!
However, if that button has a "rendered" attribute, then the PDF fails to render for some reason. (I don't want the button rendered if I'm producing a PDF, as I don't want to see it in the PDF). Instead, the page simply refreshes. This seems a little odd - any idea what's up?
Here' s the page:
<apex:page renderAs="{!chooserender}" controller="MyController" > <apex:pageBlock title="Some Page Block"> <apex:pageBlockSection title="Section 1"> Text </apex:pageBlockSection> <apex:pageBlockSection title="Section 2"> Text </apex:pageBlockSection> </apex:pageBlock> <apex:form > <apex:commandLink rendered="{!$CurrentPage.parameters.p == null}" value="PDF" action="{!deliverAsPDF}" target="_blank"></apex:commandLink> </apex:form> </apex:page>
Here's the controller:
public class MyController { public String getChooserender() { if (ApexPages.currentPage().getParameters().get('p') != null) return 'pdf'; else return null; } public PageReference deliverAsPDF() { PageReference pdf = Page.foo; pdf.getParameters().put('p','p'); return pdf; } }
I've blogged about this (sans problem) here.
I know I can solve my problem in a different way (style sheets come to mind), but I'd really like to figure out why, when a button has a rendered='false', it no longer generates a PDF. (I mean, I've already pushed it, and an action is occuring, so whether the button itself is present or not in the result shouldn't matter?)
Thanks!
With that said I would tend to simplify this even further and remove the action method all together because no decision or other logic that requires code is being made at the time of clicking - this can then be distilled to something that does not need a controller or extension, <apex:form> etc:
All Answers
With that said I would tend to simplify this even further and remove the action method all together because no decision or other logic that requires code is being made at the time of clicking - this can then be distilled to something that does not need a controller or extension, <apex:form> etc:
What about , if we had to export it to excel file instead of using the pdf.
I have a report in VF page, now I want the same page to be export to Excel. I do not want to write the same code again and just a new attribute to the page tag: "ContentType":
Thanks