I have a VF page. There I have a repeat tag. Inside it I have a component. All this page is rendered as PDF.

My intention is to start each object from a new pdf page.

I found a

  <apex:repeat value="{!listToDisplay}" var="itemToDisplay" id="theRepeat">
    <c:ItemToDisplay_Component itemIdToDisplay="{!itemToDisplay.Id}" />
    <div style="page-break-after:always">&nbsp;</div>

solution. It works just fine.

Now I want some IF statement/syntax which allows my to avoid this breaking div to appear for last item.

Please, assume that I have a method in page's controller

  public boolean isLastItem() { ... }

1 Answer 1


Having a method in the page controller won't help, as that would apply to all entries in listToDisplay. You need a method on record the repeat is processing that lets you determine whether it is the last item or not. Given that you are referring to an ID, I'm assuming that your collection consists of sobjects.

That being the case, I reckon you'll need a wrapper class to encapsulate an sobject instance and the boolean to indicate if it is the last element. Something like:

public class MyWrapper
    public My_Sobject__c sobj {get; set;}
    public Boolean last {get; set;}

    public MyWrapper(My_Sobject__c inSobj, Boolean inLast)

replacing My_Sobject__c with the API name of your sobject.

You'd then make listToDisplay a collection of MyWrapper classes and set the last property appropriately.

Finally on your page, you'd iterate the list of wrapper classes and check the instance to see if it is the last:

<apex:repeat value="{!listToDisplay}" var="itemToDisplay" id="theRepeat">
    <c:ItemToDisplay_Component itemIdToDisplay="{!itemToDisplay.sobj.Id}" />
    <apex:outputPanel layout="none" rendered="{!NOT(itemToDisplay.last)}">
        <div style="page-break-after:always">&nbsp;</div>   

Note that as you are iterating a list of the wrapper classes, you'll have to prefix any fields displayed with sobj in order to access the sobject inside the wrapper class : {!itemToDisplay.sobj.Id}

  • Do you want to tell me that I can't use method in this statement? Mar 3, 2014 at 9:28
  • Thanks! I came up with <apex:outputPanel layout="none" rendered="{!NOT(firstItemId == itemToDisplay.Id)}"> <div style="page-break-before:always">&nbsp;</div> </apex:outputPanel> Can you name this NOT function? How it is named? What are other functions like this for VF page? Mar 3, 2014 at 10:05
  • 1
    Your way will work as well, I personally go for wrapper classes most of the time as it makes them easy to extend them further. NOT is a formula operator - most of these work on VF and are documented at: help.salesforce.com/… Mar 3, 2014 at 13:13

You must log in to answer this question.

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