0

I have a custom controller and VF page. I'm trying to set up the page to render sections based upon the value of a field on the OpportunityLineItem object. However, I'm not quote sure how to get the variable to use in the Rendered component from the controller list over to my VF page.

Controller:

    String oliId;
    public list<OpportunityLineItem> listOLI{get;set;} 

    public CalculateOLISummary() {
        oliId = ApexPages.currentPage().getParameters().get('id');
    }

    public void init(){
        listOLI = new list<OpportunityLineItem>();
        listOLI = [SELECT OpportunityId, Grouping__c, Product2.Name, ProductCode, Quantity, UnitPrice, 
                   TotalPrice, Discount, ListPrice
                   FROM OpportunityLineItem
                   WHERE OpportunityId =:oliId];

    public PageReference Cancel(){
        PageReference pg = new PageReference('/' + oliId);
        return pg;
    }
}

VF Page:

    <apex:page controller="CalculateOLISummary" action="{!init}" >
        <apex:pageMessages id="pgMess" />
        <apex:form id="frmReview" > 
            <apex:pageBlock id="pgBlckQSummary" title="OLI Summary">
                <center><apex:commandButton title="Back to OPP" value="Back to Opp" action="{!cancel}"/></center>

<!-- I ONLY WANT THIS pageBlockTable to render records in my list where the Grouping__c value is TRUE -->
                <apex:pageBlockTable title="Quote Summary" value="{!listOLI}"  var="OLI">

                    <apex:column headerValue="Product">
                        <apex:outputField value="OLI.Product2"/>
                    </apex:column>
                </apex:pageBlockTable>    

            </apex:pageBlock>
        </apex:form>        
    </apex:page>
  • 1
    If I understand this right, your listOLI is a list of OpportunityLineItem records. So in that case listOLI.Grouping__c == TRUE shouldn't even compile. And that's because your conditional statement assumes that listOLI is a record instead of a list itself. Are you able to save your VF page at the first place? – Jayant Das Sep 7 '18 at 16:10
  • No, I can't get the controller to save with that line in it. I am trying to set up my VF page so 1 section renders when that value is set to True, and another when it's false. – J. Neilan Sep 7 '18 at 16:19
  • Can you edit your post to provide details as which "section" you want to display when that value is true and which "section" when its false. Remember the value is on the records so you will need to verify that field's value based on the record being iterated. – Jayant Das Sep 7 '18 at 16:22
  • I didn't have the code yet for the false, but I indicated which section I wanted to render when the Grouping__c field is TRUE. – J. Neilan Sep 7 '18 at 16:25
1

With what you are trying to achieve using the below snippet, you won't be able to do so. This code will not compile at first place because listOLI is a List and that Group__c is actually a field on your Opportunity Line Item record.

<apex:pageBlockTable title="Quote Summary" value="{!listOLI}"  var="OLI" rendered="{!listOLI.Group__c == TRUE}">

If I understand this right, you need to display this table only if the values of all Opportunity Line Item records in the list is true, you can then modify your init() method in the VF controller to only pick the records satisfying the criteria.

So the query in your controller will look like something as below:

listOLI = [SELECT OpportunityId, Grouping__c, Product2.Name, ProductCode, 
                  Quantity, UnitPrice, TotalPrice, Discount, ListPrice
           FROM OpportunityLineItem
           WHERE OpportunityId =:oliId
           AND Grouping__c = TRUE];

This will populate your listOLI only for records satisfying the criteria. And that the apex:pageBlockTable will be rendered only if the list contains record.

<apex:pageBlockTable title="Quote Summary" value="{!listOLI}"  var="OLI">

Similarly, if you want to render another apex:pageBlockTable based on FALSE criteria, you can do so with another list variable and that the condition in your query change.

listFalseOLI = [SELECT OpportunityId, Grouping__c, Product2.Name, ProductCode, 
                  Quantity, UnitPrice, TotalPrice, Discount, ListPrice
           FROM OpportunityLineItem
           WHERE OpportunityId =:oliId
           AND Grouping__c = FALSE];

<apex:pageBlockTable title="Quote Summary" value="{!listFalseOLI}"  var="falseOLI">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.