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
dev_jhdev_jh 

Unable to conditionally render Visualforce Page (Output Panel)

Hi all,

 

We are generating quotes from Salesforce using Visualforce and rendering the page as PDF.

 

We are trying to display discounts only on line items that have a discount using the following code:

 

 

<apex:repeat value="{!Opportunity.OpportunityLineItems}" var="line"> <tr> <td>{!line.PricebookEntry.Product2.ProductCode}</td> <td align="right"><apex:OutputText value="{!ROUND(line.Quantity,0)}"/></td> <td>&nbsp;{!line.Description}</td> <td align="right"><apex:OutputField value="{!line.UnitPrice}"/></td> <td align="right"><apex:OutputField value="{!line.TotalPrice}"/></td> </tr> <apex:outputPanel id="Discounts" rendered="{!IF(AND(ISPICKVAL(Opportunity.Transport_Charges__c, "Producto Level"), line.Discount__c > 0.0), true, false)}"> <tr> <td align="right" colspan="5">Descuento <apex:OutputField value="{!line.Discount__c}"/></td> </tr> </apex:outputPanel> </apex:repeat>

 

 However this is not working properly. I will explain the 2 problems we are facing:

 

  1. Rendered condition - The below formula does not work properly. Even though Transport_Charges__c is a PICKLIST fiel, Visualforce throws up an error when saying it is a text field. If we try to change the expression to Opportunity.Transport_Charges__c == "Product Level" it does not work. Any ideas why?
    IF(AND(ISPICKVAL(Opportunity.Transport_Charges__c, "Producto Level"), line.Discount__c > 0.0), true, false)
  2. Conditional line not displaying correctly - For test purposes, until we solve point 1 above, we have used a condition that always evaluates to true. Now we can see the line speciying the discount level, but the line does not print with the same length as the other lines (see image below). This does not seem to make any sense. Any help much appreciated.
Error Screen Shot

 

Best Answer chosen by Admin (Salesforce Developers) 
Federico LarsenFederico Larsen

the apex:outputPanel in the middle of the html table y breaking it, becuase put a span tag in the middle of the table.

 

hide or show the  <tr> with style="Display:None" or style="Display:"

 this way

 


<tr style="display:{!IF( condition to hide , 'None', '')}">

  <td>line content .... etc

 </tr>

 

 

Kind regards

All Answers

Edwin VijayEdwin Vijay
Try this way for your point 1.....

rendered="{!Opportunity.Transport_Charges__c == 'Producto Level' && line.Discount__c > 0.0}"

 

regarding point 2 i am not able to get your point clearly.. 

Federico LarsenFederico Larsen

the apex:outputPanel in the middle of the html table y breaking it, becuase put a span tag in the middle of the table.

 

hide or show the  <tr> with style="Display:None" or style="Display:"

 this way

 


<tr style="display:{!IF( condition to hide , 'None', '')}">

  <td>line content .... etc

 </tr>

 

 

Kind regards

This was selected as the best answer
dev_jhdev_jh
Thanks guys, much appreciated!
goabhigogoabhigo

Thanks Larsen.

goabhigogoabhigo

Hi,

Suppose if you want to display the same grouped by Product Family how will you do it? With apex class it is possible. But how it can be done without controller?

Please help.

Balakrishna RaoBalakrishna Rao
I tried the same with tr <style:display:none> and setting display: block in javascript. But style formatting is being overrided and the section is displaying with different height and width. Is there any solution to fix this.