+ Start a Discussion
kminevkminev 

Databinding with visualforce component and datatable tag

Hi,

 

I've been trying to resolve an issue with my visual force component which has a datatable with List of objects which are stored in custom controller.

 

I have <apex:inputField> on this datatable which are bound to Sobject property and any time I click on a button my apex controller does not have the changed value from the user.

 

Below is my visual force component code:

 

<apex:component access="global" allowDML="true" controller="ProposalPdfGeneratorCmpExtension" selfClosing="true"> 

   <apex:attribute access="global" name="OpportunityId" required="false" description="This is the opportunity id!" assignTo="{!OpportunityId}" type="Id" />
   <apex:attribute access="global" name="ShowProfitMarginColumn" description="This property determines whether profit margin column will be displayed." assignTo="{!showProfitMarginColumn}" type="Boolean"/>
   <apex:attribute access="global" name="ShowSignature" description="Toggles signature panel!" assignTo="{!showSignature}" type="Boolean"/>
   <apex:attribute access="global" name="ShowPremiumDiscount" description="Toggles Premium/Discount column!" assignTo="{!showPremiumDiscount}" type="Boolean"/>

    <apex:stylesheet value="{!$Resource.ProposalCss}"/>   
    
    <apex:pageMessages id="errors"/>
    
     <div align="left" style="float: left; font-size: 10pt;">
         <apex:panelGrid columns="1" styleClass="companyTable">
            <apex:outputText value="{!$Organization.Name}" styleClass="companyName"/>
            <apex:outputText value="{!$Organization.Street}"/>
            <apex:outputText value="{!$Organization.City}, {!$Organization.State} {!$Organization.PostalCode}"/>
            <apex:outputText value="{!$Organization.Phone}"/>
         </apex:panelGrid> 
     </div>       
    
      <div align="right" style="float: right;">             
         <apex:image url="{!$Resource.MY_Logo}" width="60%" height="60%"/>
      </div>
        
      <div style="clear: both;"/>     
      
       <div align="center" class="proposalTitle">
            <apex:outputLabel styleClass="proposalTitle">{!if(opportunityProposal.Proposal_Name__c != null, opportunityProposal.Proposal_Name__c, opportunityProposal.Name)}</apex:outputLabel>       
       </div> 
                
    <div style="clear: both;"/>
  
    <br/>   
    <br/>
   
    <table width="100%" class="tableProposalLines" border="1">
        
        <tr class="tablehead">
            <td width="50%">Hours / Days</td>
            <td width="50%">Monitoring</td>            
        </tr>
        
        <tr border="1">
            <td>On Call</td>
            <td>Exchange Connectivity</td>            
        </tr>    
        
        <tr border="1">
            <td>24x7</td>
            <td>Network, Wan, and Server Infrastructure</td>            
        </tr>         
    </table>
 
     <br/><br/>

    <apex:form >
  
        <apex:outputpanel id="panelTable" >
        <!--
             <apex:dataTable id="proposalDataTable" border="1" value="{!opportunityLinesShell}" var="shell" headerClass="tablehead" styleClass="tableProposalLines" width="100%">
                
                 <apex:column headerValue="Category" width="100">
                        
                        <apex:outputLabel value="{!shell.olCategory}"/>
        
                 </apex:column>
                 
                 <apex:column headerValue="Description">
                     
                     <apex:dataTable value="{!shell.OpportunityLineItems}" var="ol">
                         <apex:column >
                             <apex:outputField value="{!ol.Proposal_Description__c}"/>
                         </apex:column>
                     </apex:dataTable>
                     
                 </apex:column>
                 
                 <apex:column headerValue="Quantity">
                     
                     <apex:dataTable value="{!shell.OpportunityLineItems}" var="ol">
                         <apex:column >
                             <apex:inputField style="text-align: center;"  value="{!ol.Count__c}"/>
                         </apex:column>
                     </apex:dataTable>
                     
                 </apex:column>   
                
                <apex:column headerValue="Premium / Discount %" width="95" rendered="{!showPremiumDiscount}">
                     
                     <apex:dataTable value="{!shell.OpportunityLineItems}" id="premiumDiscountTable" var="ol">
                         <apex:column >
                            
                            <apex:outputField value="{!ol.Premium_Discount_Percent__c}" />
    
    
                         </apex:column>
                     </apex:dataTable>
                     
                 </apex:column>
                
                <apex:column headerValue="Retail Price Per" width="95" id="priceColumn" >
                     
                     <apex:dataTable value="{!shell.OpportunityLineItems}" var="ol">
                         <apex:column >
                         
                                 <apex:inputField value="{!ol.Retail_Price__c}" />
           
                         </apex:column>
                     </apex:dataTable>
                     
                 </apex:column>
        
                       <apex:column headerValue="Subtotal" width="95" >
                     
                     <apex:dataTable value="{!shell.OpportunityLineItems}" var="ol">
                         <apex:column >
                             <apex:outputField value="{!ol.Total_Sale_Price__c}"/>
                         </apex:column>
                     </apex:dataTable>
                     
                 </apex:column> 
                 
                  <apex:column headerValue="Profit Margin%" rendered="{!showProfitMarginColumn}">
                      <apex:dataTable value="{!shell.OpportunityLineItems}" var="ol">
                         <apex:column >
                            <apex:outputField value="{!ol.Profit_Margin_Percent__c}"/>
                         </apex:column>
                     </apex:dataTable>
                 </apex:column>
                                        
             </apex:dataTable>
            -->

         <apex:dataTable value="{!opportunityLineItems}" var="ol">
             <apex:column >
                 <apex:inputField value="{!ol.Retail_Price__c}"/>
             </apex:column>
         </apex:dataTable>
         
         </apex:outputpanel>
         
    </apex:form> 

    <div style="clear: both;"/>    
    <br/>
    
    <div style="float: right; font-size: 7pt;">    
     
     <table class="tablehead">
        <tr>
            <td width="175px">Total One-Time Fee Estimate:</td>
             <td><apex:outputField value="{!opportunityProposal.SOME_FIELD}"/></td>       
        </tr>    
        
        <tr>
            <td>Total Recurring Monthly Fee Estimate:</td>
             <td><apex:outputField value="{!opportunityProposal.SOME_FIELD}"/></td>       
        </tr>  
        
        <tr>
            <td><div style="{!if(showProfitMarginColumn, "display:inline;", "display:none;")}">Profit Margin:</div></td>
            <td><apex:outputField value="{!opportunityProposal.Profit_Margin__c}" rendered="{!showProfitMarginColumn}"/></td>
        </tr>   
        <tr>
            <td><div style="{!if(showProfitMarginColumn, "display:inline;", "display:none;")}">Profit Margin%:</div></td>
            <td><apex:outputField value="{!opportunityProposal.Profit_Margin_Percent__c}" rendered="{!showProfitMarginColumn}"/></td>
        </tr>
        </table>     
        
    </div>      
    
    <div style="clear: both;"/>
     <br/><br/><br/>   
   
    <apex:dataTable border="1" styleClass="tableProposalLines" value="{!termsAndConditions}" var="tnc" width="100%" >
        <apex:column >
            {!if((tnc.T_s_C_s_Proposal_Line__c != null || tnc.T_s_C_s_Proposal_Line__c != ""), tnc.T_s_C_s_Proposal_Line__c, tnc.T_s_C_s_Pre_Defined_Proposal_Line__c)}
        </apex:column>
    </apex:dataTable> 

    <c:Proposal_Signature_Cmp id="proposalSignatureCmp" rendered="{!showSignature}"/>
    
    <apex:form >
        <div align="center">
            <br/>
            <apex:commandButton value="Save Proposal Changes" action="{!persistProposalWithOpportunity}" rerender="panelTable" />
        </div>
    </apex:form>
   
</apex:component>

 

More code will follow...

 

I am out of options at this point I tried everything.

kminevkminev
 And this is my controller:
 
public class ProposalPdfGeneratorCmpExtension {
	
	// this constructor is intended for a vforce component
    public ProposalPdfGeneratorCmpExtension() {
            
        String oppIdTemp = ApexPages.currentPage().getParameters().get('id');
            
        if (oppIdTemp != null && oppIdTemp != '') {
            OpportunityId = oppIdTemp;
        }

        showProfitMarginColumn = false;
        showSignature = false;
        showPremiumDiscount = false;
    }
    
    private void loadSkuRecordTypes() {

        skuRecordTypesMap = new Map<String, String>();
        
        List<Schema.RecordTypeInfo> recordTypeInfos = SKU__c.sObjectType.getDescribe().getRecordTypeInfos();
        
        for (Schema.RecordTypeInfo rTypeInfo : recordTypeInfos) {
            if (rTypeInfo.isAvailable() && rTypeInfo.getName() != 'Master') {
                skuRecordTypesMap.put(rTypeInfo.getRecordTypeId(), rTypeInfo.getName());
            }
        }        
    
    }
    
    private void queryTermsAndConditionsForOpportunity(String opportunityId) {
            
        try {
            
            termsAndConditions = [SELECT Id, T_s_C_s_Pre_Defined_Proposal_Line__c, T_s_C_s_Proposal_Line__c, Use__c
                                            FROM T_s_C_s_Terms_Conditions__c WHERE Opportunity__c = :opportunityId];
            
        }catch (System.Exception ex) {
            System.debug('Exception while querying for Terms and Conditions Line Items! Exception: ' + ex.getMessage());
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error: ' + ex.getMessage()));
        }
        
    }
    
    public void queryOpportunityLineItemsForOpportunity(String opportunityId){
        
        try {
            
            opportunityLineItems = [SELECT Id, Name, Description__c, Category__c, Count__c, Count_Type__c, Retail_Price__c, Sale_Price__c, Cost__c,
                                            Total_Sale_Price__c, SKU__r.RecordTypeId, Proposal_Category__c, Premium_Discount_Percent__c,
                                            Revenue_Type__c, Proposal_Description__c, Profit_Margin__c, Profit_Margin_Percent__c
                                            FROM Opportunity_Line_Item__c WHERE Opportunity__c = :opportunityId order by Proposal_Category__c, Proposal_Description__c];
            
            
        }catch (System.Exception ex) {
            System.debug('Exception while querying for Opportunity Line Items! Exception: ' + ex.getMessage());
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error: ' + ex.getMessage()));
        }
    }
        
    public PageReference persistProposalWithOpportunity() {
            
        try {
            
            // TEST HERE WHERE IT NEEDS TO SAVE
            
            for (Opportunity_Line_Item__c test :opportunityLineItems) {
                System.debug('ol2.name: ' + test.name + ' Retail_price: ' + test.Retail_Price__c);
                update opportunityLineItems;
            }
            // TEST HERE WHERE IT NEEDS TO SAVE
            
            if (opportunityLinesShell != null && opportunityLinesShell.size() > 0) {
                
                List<Opportunity_Line_Item__c> olsTemp = new List<Opportunity_Line_Item__c>();
                
                for (OpportunityLineCategory shellTemp :opportunityLinesShell) {
                    for (Opportunity_Line_Item__c olTemp :shellTemp.getOpportunityLineItems()) {
                        System.debug('ol.name: ' + olTemp.Name + ' Retail_Price: ' + olTemp.Retail_Price__c);
                        olsTemp.add(olTemp);
                    }
                }
                
                update olsTemp;
            } else {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, 'WARNING: Opportunity Line Items collection was empty or null!'));
            }
        }catch(System.Exception ex) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error: ' + ex.getMessage()));
            return null;
        }
        
        return null;
    }
        
    public void fillShell() {
            
        if (opportunityLineItems != null && opportunityLineItems.size() > 0) {
                
            opportunityLinesShell = new List<OpportunityLineCategory>();
            
            OpportunityLineCategory olCategory = new OpportunityLineCategory(opportunityLineItems[0].Proposal_Category__c);
            
            olCategory.addOpportunityLineItem(opportunityLineItems[0]);
            
            for (Integer i = 1; i < opportunityLineItems.size(); i++) {
                    
                if (opportunityLineItems[i].Proposal_Category__c == olCategory.getOlCategory()) {
                    olCategory.addOpportunityLineItem(opportunityLineItems[i]);
                } else {
                    
                    opportunityLinesShell.add(olCategory);
                     
                    olCategory = new OpportunityLineCategory(opportunityLineItems[i].Proposal_Category__c);
                                        
                    olCategory.addOpportunityLineItem(opportunityLineItems[i]);
                }
            }
            opportunityLinesShell.add(olCategory);
        }
    }
        
    public PageReference previewAsPdf() {
       
        PageReference previewPage = Page.ProposalPdfPreview;
        
        previewPage.getParameters().put('id', this.opportunityProposal.Id);
        
        previewPage.setRedirect(true);
        
        return previewPage;    
    }
    
    // private variables
    private static String RECORD_TYPE_SKU = '01250000000DteHAAS';
    private Map<String, String> skuRecordTypesMap;//<Id, Name>
    
    // public variables
    public Opportunity opportunityProposal { get; set;}
    
    public String notifRole = 'Proposal & Exhibit NOTIFICATION';
    
    public List<OpportunityLineCategory> opportunityLinesShell {get; set;}
        
    public List<Opportunity_Line_Item__c> opportunityLineItems {get; set;}
    
    public List<T_s_C_s_Terms_Conditions__c> termsAndConditions{get; set;}
    
	public Boolean showSignature {get; set;}
        
    public Boolean showProfitMarginColumn { get; set;}
    
    public Boolean showPremiumDiscount { get; set; }
    
    public Id OpportunityId {
    
        get { return OpportunityId;}
        
        // This set method acts as constructor due to the order of execution on vforce components and not being able to capture Opportunity id before setter executed!
        // Only used when the component is used as a stand-alone when used as a dynamicComponent other logic is used
        set {
            
            if (value != null) {
                OpportunityId = value;
            }
            
            try {            
                    
                opportunityProposal = [SELECT Name, Id, Proposal_Name__c, Exhibit_Name__c, Account.Name, SOME_field, Term__c, Profit_Margin__c, Profit_Margin_Percent__c FROM Opportunity WHERE Id = :OpportunityId limit 1][0];
                loadSkuRecordTypes();
                
                queryOpportunityLineItemsForOpportunity(opportunityProposal.Id);
                queryTermsAndConditionsForOpportunity(opportunityProposal.Id);
                fillShell();
                    
            }catch (System.Exception ex) {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error while setting OpportunityId: ' + ex.getMessage()));
            }
            
        }
    }
    
	public class OpportunityLineCategory {
        
        private String opportunityLineCategory;
        private List<Opportunity_Line_Item__c>opportunityLineItems;
        
        public OpportunityLineCategory(String olCategory){
            this.opportunityLineCategory = olCategory;
        }
        
        public String getOlCategory(){
            return opportunityLineCategory;
        }
        
        public void setOlCategory(String olCategory){
            this.opportunityLineCategory = olCategory;
        } 
        
        public List<Opportunity_Line_Item__c> getOpportunityLineItems(){
            return this.opportunityLineItems;
        }
        
        public void getOpportunityLineItems(List<Opportunity_Line_Item__c> ols){
            this.opportunityLineItems = ols;
        }
        
        public void addOpportunityLineItem(Opportunity_Line_Item__c ol){
        
            if (this.opportunityLineItems == null) {
                this.opportunityLineItems = new List<Opportunity_Line_Item__c>();
            }
            
            opportunityLineItems.add(ol);
        }        
    }
}
 
Also this is the visual force page where this component is used:
 
<apex:page tabStyle="Opportunity" standardController="Opportunity" extensions="ProposalPdfExtension"> 
    
    <apex:pageMessages id="errors" rendered="false"/>
    
    <apex:stylesheet value="{!$Resource.ProposalCss}"/>
    
 
    <apex:form >
      <apex:actionFunction name="emailParamsToApex" action="{!sendExhibit}" rerender="emailPageBlock">
          <apex:param name="emailSubject" value=""/>
          <apex:param name="emailBody" value="" />
          <apex:param name="isExhibit" value="false"/>
      </apex:actionFunction>
    </apex:form>
        
    
        <apex:pageBlock title="Proposal Builder">
            
              <apex:form >
              <apex:pageBlockSection title="Opportunity">
                      <apex:pageblockSectionItem >
                          <apex:outputLink value="https://cs4.salesforce.com/{!Opportunity.Id}">{!Opportunity.Name}</apex:outputLink>
                      </apex:pageblockSectionItem>
                      
              </apex:pageBlockSection>
              
              </apex:form>
        </apex:pageBlock>

    
    <div style="width: 75%; margin-left: auto; margin-right: auto;">
        <apex:pageBlock title="Proposal PDF Review" id="pageBlockCmp">      
            
            <apex:dynamicComponent componentValue="{!proposalPdfGeneratorCmp}"/>
            
  
        </apex:pageBlock>
    </div>
    
    <br/><br/><br/>
  
    <apex:form >
    <apex:pageBlock id="emailPageBlock" title="Email Proposal / Exhibit">
         
        <apex:pageBlockSection columns="1" collapsible="true">
            
            <table>
                <tr>
                    <td>Subject</td>
                    <td><input type="text" id="txtEmailSubject" style="width: 700px;"/></td>
                </tr>
                <tr>
                    <td>From</td>
                    <td>{!$User.Email}</td>
                </tr>
                <tr>
                    <td>To</td>
                    <td>{!contactRoleProposalRecipients}</td>
                </tr>
                <tr>
                    <td>Email Body</td>
                    <td><textarea  id="txtEmailBody" cols="130" rows="12" /></td>
                </tr>
                <tr>
                    <td>Attachment</td>
                    <td>Proposal will be attached along with the email as pdf and will not include profit margin, discount and premium columns!!!</td>
                </tr>
            </table>
                            
        </apex:pageBlockSection>
        <apex:pageBlockButtons >
        
            <apex:commandButton value="Send Proposal" rendered="{!isOpportunityApproved}" onclick="emailParams(false);" status="emailStatus" rerender="null"/>
            <apex:commandButton value="Send Exhibit" rendered="{!isOpportunityApproved}" onclick="emailParams(true);" rerender="null"/>
            <apex:actionStatus id="emailStatus" startText="Please wait..."/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
    
    </apex:form>
    
    
   <apex:relatedList list="OpportunityContactRoles" pageSize="3"/>
   <apex:relatedList list="ProcessSteps" pageSize="2"/>
   <apex:relatedList list="ActivityHistories"/>
   
   <apex:includeScript value="{!URLFOR($Resource.jquery, 'js/jquery-1.6.2.min.js')}"/>
   <apex:includeScript value="{!URLFOR($Resource.jquery, 'js/jquery-ui-1.8.16.custom.min.js')}"/>
  
   <script type="text/javascript">
         
         var j$ = jQuery.noConflict();
         
         function emailParams(isExhibit) {
            
             var strEmailSubject = document.getElementById("txtEmailSubject").value;
             var strEmailBody = document.getElementById("txtEmailBody").value;
             
             if (strEmailSubject == "" || strEmailBody == "") {
                 alert("You must enter email subject and body before sending to clients!");
             } else {
                 emailParamsToApex(strEmailSubject , strEmailBody, isExhibit);
             }
         }

   </script>
    
</apex:page>
 

 

kminevkminev
And this is the visual force controller:
 
public class ProposalPdfExtension {
        
        public ProposalPdfExtension(ApexPages.StandardController ctrl) {
            
            controller = ctrl;
            opportunityProposal = [SELECT Name, Id, Proposal_Name__c, Account.Name, SOMEFIELDS, Term__c, Profit_Margin_Percent__c, Profit_Margin__c FROM Opportunity WHERE Id = :controller.getId() limit 1][0];
            checkOpportunityForApproval();
        }
        
        public String getContactRoleProposalRecipients() {
            
            try {
                String strRecipients = '';
                List<OpportunityContactRole> opportunityContactRoles = [SELECT Id, ContactId, Role, Contact.Email FROM OpportunityContactRole WHERE OpportunityId = :opportunityProposal.Id AND Role = :notifRole];
                
                if (opportunityContactRoles != null && opportunityContactRoles.size() > 0) {
                    
                    for (OpportunityContactRole cr :opportunityContactRoles) {
                        if (cr.Contact.Email != null) {
                            strRecipients += cr.Contact.Email + '; ';
                        }
                    }
                    
                    return strRecipients;
                }
                
            }catch(System.Exception ex) {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error: ' + ex.getMessage()));
            }
            return '';
        }
        
        public void sendExhibit() {
            
            try {
                
                String strEmailSubject = ApexPages.currentPage().getParameters().get('emailSubject');
                String strEmailBody = ApexPages.currentPage().getParameters().get('emailBody');
                String strIsExhibit = ApexPages.currentPage().getParameters().get('isExhibit');
                
                List<OpportunityContactRole> opportunityContactRoles = [SELECT Id, ContactId, Role, Contact.Email FROM OpportunityContactRole WHERE OpportunityId = :opportunityProposal.Id AND Role = :notifRole];
                List<String> recipients = new List<String>();
                
                if (opportunityContactRoles != null && opportunityContactRoles.size() > 0) {
                    
                    for (OpportunityContactRole cr :opportunityContactRoles) {
                        if (cr.Contact.Email != null) {
                            recipients.add(cr.Contact.Email);
                        }
                    }
                    
                    if (recipients != null && recipients.size() > 0) {
                        
                        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                        
                        mail.setToAddresses(recipients);
                        mail.setSubject(strEmailSubject);
                        mail.setPlainTextBody(strEmailBody);
                        
                        // convert proposal to pdf
                        PageReference pdfPage = Page.proposalpdfpreview;
                        //PageReference pdfPage = Page.testKirilMinev;
                        
                        pdfPage.getParameters().put('id', opportunityProposal.id);
                        /* generate the pdf blob */
                        Blob pdfBlob = pdfPage.getContent();
                        
                        
                        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
                        
                        attachment.setBody(pdfBlob);
                        
                        if (strIsExhibit.equalsIgnoreCase('false')) {
                            attachment.setFileName(strEmailSubject + '_Proposal_' + datetime.now() + '.pdf');
                        } else {
                            attachment.setFileName(strEmailSubject + '_Exhibit_' + datetime.now() + '.pdf');
                        }

                        //attachment.setContentType('application/pdf');
                        
                        mail.setFileAttachments(new Messaging.EmailFileAttachment[]{attachment});
                        
                        Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});
                        
                        // This task will be logged as an activity under the activity history ralted list
                        Task activityTask = createActivityTaskFromEmail(mail, attachment.getFileName());
                        
                        if (activityTask != null) {
                            insert activityTask;
                        }
                        
                        saveProposalAsOpportunityAttachment();
                    }
                }
            }catch (System.Exception ex) {
                System.debug('Exception in sendExhibit() Message: ' + ex.getMessage());
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error: ' + ex.getMessage()));
            }
        }
        
        public Task createActivityTaskFromEmail(Messaging.SingleEmailMessage mail, String fileAttachmentName) {
            
            Task activityTask = new Task();
            
            if (mail != null) {
                
                activityTask.Subject = 'EMAIL: ' + mail.getSubject();
                
                if (fileAttachmentName != null && fileAttachmentName != '') {
                    activityTask.Description = 'Email Body:\n' + mail.getPlainTextBody() + '\nAttachment: [' + fileAttachmentName + ']';
                } else {
                    activityTask.Description = mail.getPlainTextBody();
                }
                
                activityTask.Status = 'Completed';
                activityTask.Priority = 'Normail Impact';
                activityTask.WhatId = opportunityProposal.Id;
                
                return activityTask;
            }   
            return null;
        }
        
        public Boolean checkOpportunityForApproval() {
            
            if (this.opportunityProposal != null && opportunityProposal.Id != null) {
                
                List<ProcessInstance> processInstances = [select Id, Status, CreatedDate from ProcessInstance where TargetObjectId = :opportunityProposal.Id Order By CreatedDate desc limit 1];
                
                if (processInstances != null && processInstances.size() == 1) {
                    
                    if (processInstances[0].Status == 'Approved') {
                        isOpportunityApproved = true;
                        return true;
                    } else {
                        isOpportunityApproved = false;
                        return false;
                    }
                }
            } 
            return false;
        }
        
        public PageReference saveProposalAsOpportunityAttachment() {
            
            PageReference pdfPage = Page.proposalpdfpreview;
            
            /* set the quote id on the page definition */
            pdfPage.getParameters().put('id',opportunityProposal.id);
            
            /* generate the pdf blob */
            Blob pdfBlob = pdfPage.getContent();
            
            /* create the attachment against the quote */
            Attachment a = new Attachment(parentId = opportunityProposal.id, name = opportunityProposal.Name + '_' + datetime.now() + '_.pdf', body = pdfBlob);
            
            /* insert the attachment */
            insert a;
            
            /* send the user back to the quote detail page */
            return controller.view();
        }
        
        public Component.c.Proposal_Pdf_Generator_Cmp getProposalPdfGeneratorCmp() {
            
            try {
                // Retrieve the opportunity id from the query string
                String oppId = ApexPages.currentPage().getParameters().get('id');
                
                if (oppId == null) {
                    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error: OpportunitId cannot be null!'));
                    return null;
                }
                
                // set to false if null as this is not invoked on the constructor above
                if (showProfitMarginColumn == null) {
                    showProfitMarginColumn = true;
                }
                
                // set to false if null as this is not invoked on the constructor above
                if (showSignature == null) {
                    showSignature = false;
                }
                
                // set to false if null as this is not invoked on the constructor above
                if (showPremiumDiscount == null) {
                    showPremiumDiscount = true;
                }
                
                
                return new Component.c.Proposal_Pdf_Generator_Cmp(OpportunityId = opportunityProposal.Id, 
                                                                            showProfitMarginColumn = this.showProfitMarginColumn, 
                                                                            showSignature = this.showSignature, 
                                                                            showPremiumDiscount = this.showPremiumDiscount);
                
            }catch (System.Exception ex) {
                System.debug('Exception in getProposalPdfGeneratorCmp(): ' + ex.getMessage());
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error: ' + ex.getMessage()));
                return null;
            }   
        }
        
        // Variables and getter and setters declaration   
        public ApexPages.StandardController controller;
        
        public String notifRole = 'Proposal & Exhibit NOTIFICATION';
        
        public Opportunity opportunityProposal { get; set;}
        
        public String emailSubject {get; set;}
        
        public String emailBody {get; set;}
        
        public Boolean isOpportunityApproved { get; set;}
        
        public Boolean showSignature {get; set;}
        
	    public Boolean showProfitMarginColumn { get; set;}
	    
	    public Boolean showPremiumDiscount { get; set; }
        

}