5

I have the following code:

<ul data-role="listview" data-filter="false">
    <apex:repeat value="{!Proposals}" var="item">
        <li>
            <a href="{!$Page.aa_rg_jm_proposal}?id={!item.Proposal.ID}">{!item.Proposal.Name}</a> 
            <span class="ui-li-count">{!item.LineCount}</span>
        </li>
    </apex:repeat>
</ul>

I want to prevent a line item (e.g. <li>..<li>) from being rendered if item.LineCount = 0.

I tried adding a rendered attribute to the <apex:repeat> tag like so:

<apex:repeat value="{!Proposals}" var="item" 
    rendered="{!IF(item.LineCount > 0, true, false)}">

but it won't take it.

Is there a way to achieve something like this in visualforce?

P.S. I am aware that I can easily filter the collection in the controller, but I want to know if there is a way to do it the way I outlined.

2
  • What do you mean by "it won't take it"? Are you getting an error or is it just not working? Is LineCount an integer? – Mike Chale Sep 12 '13 at 21:19
  • @MikeChale I should have said, it doesn't have the desired effect. – AngryHacker Sep 12 '13 at 21:28
7

Yes, you just need to wrap the output in something you can render selectively such as an outputpanel.

<ul data-role="listview" data-filter="false">
    <apex:repeat value="{!Proposals}" var="item">
        <apex:outputPanel rendered="{!item.LineCount > 0}">
            <li>
                <a href="{!$Page.aa_rg_jm_proposal}?id={!item.Proposal.ID}">{!item.Proposal.Name}</a> 
                <span class="ui-li-count">{!item.LineCount}</span>
            </li>        
        </apex:outputPanel>
    </apex:repeat>
</ul>
3
  • This produces the intended result, but it also wraps a span tag around each <li> and completely messes up the styling. Is there a way to prevent that? – AngryHacker Sep 12 '13 at 21:31
  • 1
    yes, take a look at the layout attribute for outputpanels in the visualforce api documentation, there are a couple options you have to control what the resulting html is, include no html – Ralph Callaway Sep 12 '13 at 21:32
  • 3
    Perfect. layout="none" did the trick. Thanks a bunch! – AngryHacker Sep 12 '13 at 21:38

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.