Created
February 9, 2012 23:28
-
-
Save joshbirk/1784230 to your computer and use it in GitHub Desktop.
Another Wizard Example (with PDF)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class DataPoint { | |
| public Boolean isPrint {get; set;} | |
| public Boolean isEmail {get; set;} | |
| public Contact contactData {get; set;} | |
| public DataPoint(Contact c) { | |
| contactData = c; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <apex:page controller="WizardExample" > | |
| <apex:form > | |
| <apex:commandButton action="{!previewPDF}" value="Preview PDF" /> | |
| <input type="checkbox" onclick="checkAll(this,'Selectd_Print')" />Print All / | |
| <input type="checkbox" onclick="checkAll(this,'Selectd_Email')" />Email All | |
| <script type="text/javascript"> | |
| function checkAll(cb,filter) | |
| { | |
| var inputElem = document.getElementsByTagName("input"); | |
| for(var i=0; i<inputElem.length; i++) | |
| { | |
| if(inputElem[i].id.indexOf(filter)!=-1) | |
| inputElem[i].checked = cb.checked; | |
| } | |
| } | |
| </script> | |
| <apex:dataTable value="{!points}" var="point"> | |
| <apex:column ><apex:facet name="header">Name</apex:facet><apex:outputField value="{!point.contactData.Name}" /></apex:column> | |
| <apex:column ><apex:facet name="header">Print</apex:facet><apex:inputCheckbox id="Selectd_Print" value="{!point.isPrint}"/></apex:column> | |
| <apex:column ><apex:facet name="header">Email</apex:facet><apex:inputCheckbox id="Selectd_Email" value="{!point.isEmail}"/></apex:column> | |
| </apex:dataTable> | |
| </apex:form> | |
| </apex:page> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <apex:page controller="WizardExample" renderAs="{!contentType}" showHeader="false" > | |
| <apex:form rendered="{!contentType != 'PDF'}"> | |
| <apex:commandButton action="{!showPDF}" value="Generate PDF" /> | |
| </apex:form> | |
| <h1>My Contacts</h1> | |
| <apex:repeat value="{!contactsToPrint}" var="contact"> | |
| <apex:outputText value="{!contact.Name}" /><HR /> | |
| </apex:repeat> | |
| </apex:page> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class WizardExample { | |
| public transient List<Contact> contacts {get; set;} | |
| public List<DataPoint> points {get; set;} | |
| public List<Contact> contactsToPrint {get; set;} | |
| public List<Contact> contactsToEmail {get; set;} | |
| public String contentType {get; set;} | |
| public WizardExample() { | |
| contentType = 'html'; | |
| contacts = [SELECT ID, Name from Contact LIMIT 100]; | |
| points = new List<DataPoint>(); | |
| for(Contact c : contacts) { | |
| points.add(new DataPoint(c)); | |
| } | |
| } | |
| public PageReference previewPDF() { | |
| contactsToPrint = new List<Contact>(); | |
| contactsToEmail = new List<Contact>(); | |
| for(DataPoint point : points) { | |
| if(point.isPrint) { | |
| contactsToPrint.add(point.contactData); | |
| } | |
| if(point.isEmail) { | |
| contactsToEmail.add(point.contactData); | |
| } | |
| } | |
| points.clear(); | |
| return Page.StepTwo; | |
| } | |
| public PageReference showPDF() { | |
| contentType = 'PDF'; | |
| return Page.StepTwo; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment