0

All,

I am trying to create a visual display of a list of contacts that are considered "High" influence. There is a pick-list field within the contact object that can be set to this value. I am using apex:repeat to create the list and would like to use "rendered =" to filter out the unimportant contacts.

              <apex:repeat value="{!Account.Contacts}" var="con" rows="6">
                    <tr>
                        <td class = "entry"><apex:outputField value="{!con.Name}" rendered=" {!con.Influence__c = 'High'}" styleClass="entry"/></td>
                        <td class = "entry"><apex:outputField value="{!con.Title}" rendered=" {!con.Influence__c = 'High'}"/></td>
                        <td class = "entry"><apex:outputField value="{!con.Owner.Name}" rendered=" {!con.Influence__c = 'High'}"/></td>
                    </tr>
                </apex:repeat>

For some reason it displays no values, even though I know there to be some. When I remove the "rendered" attribute, it works.

I appreciate any help that can be given.

  • First thing I notice is that you have an empty space at the start of the rendered expression but it may not be the cause of the issue. In the repeat block you should try displaying {!con.Influence__c} and {!con.Influence__c = 'High'} to verify that they are the values you are expecting. – BarCotter Sep 8 '15 at 20:12
  • FYI you're going to have an empty row in your table for every contact that isn't considered a "High" infleunce – BarCotter Sep 8 '15 at 20:14
  • @BarCotter I figured that might be why its not working. Is there a way to filter the subset before the repeat comes into play, or do I need a controller extension for that? – Ramin Mohammadi Sep 8 '15 at 20:17
  • 1
    You could try putting an apex:outputPanel around the tr tags: <apex:outputPanel layout="none" rendered="{!con.Influence__c = 'High'}"> – BarCotter Sep 8 '15 at 20:22
  • +1 to BarCotter, by wrapping your output fields in output panels it won't show the white space – EricSSH Sep 8 '15 at 21:58
0

You can use <apex:dataTable tag to get the required output . You can put the rendered attribute for each column based on your condition. Hope this helps.

<apex:page showHeader="true" sidebar="true" standardController="Account" tabStyle="Account">
    <apex:dataTable value="{!Account.Contacts}" var="con" cellPadding="4" border="1">
        <apex:column value="{!con.FirstName}" rendered="{!con.Influence__c=='High'}"/>
        <apex:column value="{!con.LastName}" rendered="{!con.Influence__c=='High'}"/>
        <apex:column value="{!con.Phone}" rendered="{!con.Influence__c=='High'}"/>
        <apex:column value="{!con.Email}" rendered="{!con.Influence__c=='High'}"/>
    </apex:dataTable>
</apex:page>
0

Building off Saroj Bera's answer, this should work.. But it will bloat your viewstate

<apex:page showHeader="true" sidebar="true" standardController="Account" tabStyle="Account">
<apex:dataTable value="{!Account.Contacts}" var="con" cellPadding="4" border="1">
     <apex:outputPanel rendered="{!con.Influence__c == 'High'>
        <apex:column value="{!con.FirstName}" />
    </apex:outputPanel>
     <apex:outputPanel rendered="{!con.Influence__c == 'High'>
        <apex:column value="{!con.LastName}" />
    </apex:outputPanel>
    <apex:outputPanel rendered="{!con.Influence__c == 'High'>
        <apex:column value="{!con.Phone}" />
    </apex:outputPanel>
    <apex:outputPanel rendered="{!con.Influence__c == 'High'>
        <apex:column value="{!con.Email}" />
    </apex:outputPanel>
</apex:dataTable>

  • <apex:outputPanel can not be used here as <apex:column> must be the direct child of <apex:dataTable>. Also I could not understand the meaning of "bloat your viewstate". Can you please explain. – Saroj Bera Sep 8 '15 at 23:26
  • aw really.. hm there must be a way to do that, maybe use outputText instead of columns.. but View state is developer.salesforce.com/page/… – EricSSH Sep 9 '15 at 17:11

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.