+ Start a Discussion
Naresh Krishna.ax1176Naresh Krishna.ax1176 

how can I know is there a next item exists or not in apex:repeat

Hi All,

 

I am repeating list and displaying the list items.

On each iteration am appending the comma ( , ) for separation.

But there is an extra "," at the end of the text.

 

code used:-

 

<apex:repeat value="{!ulist.userGroups}" var="userGroups">
   <apex:commandLink action="{!groupDetails}" style="text-decoration: none;color: #0066CC;">
     <apex:outputText value="{!userGroups.groupName}"/>
     <apex:outputText rendered="{!(ulist.userGroups.size > 1)}"> , </apex:outputText>                                   
   </apex:commandLink>                                
</apex:repeat>

 

how can I know is there a next item exists or not in apex:repeat ?

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Naresh Krishna.ax1176Naresh Krishna.ax1176

Got the solution :)

 

<apex:variable value="{!0}" var="num" />                            
                            <apex:repeat value="{!ulist.userGroups}" var="userGroups">
                                <apex:variable var="num" value="{!num + 1}"/>
                                <apex:commandLink action="{!groupDetails}" style="text-decoration: none;color: #0066CC;">
                                    <apex:outputText value="{!userGroups.groupName}"/>
                                       <apex:outputText rendered="{!(num < ulist.userGroups.size)}">,&nbsp;&nbsp;</apex:outputText>                                   
                                </apex:commandLink>                                
                            </apex:repeat>