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
    Commented Sep 12, 2013 at 21:19
  • @MikeChale I should have said, it doesn't have the desired effect. Commented Sep 12, 2013 at 21:28

1 Answer 1

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? Commented Sep 12, 2013 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 Commented Sep 12, 2013 at 21:32
  • 3
    Perfect. layout="none" did the trick. Thanks a bunch! Commented Sep 12, 2013 at 21:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .