我正在建立一个visualforce页面,其中有一个apex:datatable,其中包含几列。
现在,我希望仅在其值不为null且> 0时显示“折扣”列。
我的代码如下:
<apex:dataTable width="100%" value="{!Opportunity.OpportunityLineItems}" var="oli">
<apex:column width="50%" headerClass="tableheaderleft" styleClass="tablebodyleft">
<apex:facet name="header">Bezeichnung</apex:facet>
<apex:OutputField value="{!oli.Name}"/>
</apex:column>
<apex:column width="{!If(oli.Discount!=null,If((oli.Discount>0),"10%","10%"),"10%")}" headerClass="tableheadercenter" footerClass="tablefootercenter" styleClass="tablebodycenter">
<apex:facet name="header">Anzahl</apex:facet>
<apex:OutputField value="{!oli.Quantity}"/>
<apex:facet name="footer"></apex:facet>
</apex:column>
<apex:column width="20%" headerClass="tableheaderright" styleClass="tablebodyright">
<apex:facet name="header">Einzelbetrag</apex:facet>
<apex:OutputField value="{!oli.UnitPrice}"/>
<apex:facet name="footer"></apex:facet>
</apex:column>
<apex:column rendered="{!If(oli.Discount!=null,(oli.Discount>0),false)}" headerClass="tableheadercenter" footerClass="tablefootercenter" styleClass="tablebodycenter">
<apex:facet name="header">Rabatt</apex:facet>
<apex:OutputField value="{!oli.Discount}"/>
<apex:facet name="footer"></apex:facet>
</apex:column>
<apex:column width="20%" headerClass="tableheaderright" styleClass="tablebodyright">
<apex:facet name="header">Gesamtbetrag</apex:facet>
<apex:OutputField value="{!oli.TotalPrice}"/>
<apex:facet name="footer"></apex:facet>
</apex:column>
</apex:dataTable>
但是我总是得到以下异常:
javax.faces.FacesException:core.apexpages.exceptions.ApexPagesDeveloperException:运算符“>”的参数类型错误。
有人知道为什么会发生这种异常吗?因为Discount返回百分比值,会发生这种情况吗?
非常感谢!
您在注释中澄清了“仅在至少一行具有值的情况下才希望显示整个列”。
从Opp订单项到Opp,您是否有与折扣相关的汇总汇总字段?您可以做类似rendered="{!Opportunity.DiscountLinesCount__c > 0}"
或的事情{!Opportunity.TotalDiscount__c > 0}
。
如果您有顶点控制器(或扩展名),则可以检查行并设置一些布尔标志,然后根据该标志进行渲染。那是官方的方法。
非正式地,您可以在dataTable之前遍历所有订单项,从而滥用<apex:variable>
代码。有点hack,但是可以在没有任何顶点的情况下工作。检查我对这个问题的回答:https : //salesforce.stackexchange.com/q/193169/799
这样的事情。没有尝试运行它,但应该给您想法。
<apex:variable var="hasDiscountLines" value="{!false}" />
<apex:repeat value="{!Opportunity.OpportunityLineItems}" var="oli">
<apex:variable var="hasDiscountLines" value="{!hasDiscountLines || oli.Discount != null}" />
</apex:repeat>
(...)
<apex:dataTable width="100%" value="{!Opportunity.OpportunityLineItems}" var="oli">
<apex:column rendered="{!hasDiscountLines}">
(...)
</apex:dataTable>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句