+ Start a Discussion

How to loop 6 times?

Hi, I have this html in a visual force page. I am trying to repeat this code 6 times. Is there a for-loop function in apex that will allow me to do this.

such as

for (int x=0; x6; x++){

<table style="width:700px"><tr>
<td valign="middle" align="center">
<br/><br/><h1>Commercial Invoice</h1>
<img id="theImage" src="https://na1.salesforce.com/servlet/servlet.FileDownload?file=01530000000mvyc" />



Message Edited by Alexandre on 05-25-2009 07:18 AM
why can't you copy and paste six times?  This is a visualforce page and not apex.  If you want to use the <apex:repeat tag then you will need a controller with list property with 6 elements
It cant copy paste because its 17 pages long and it changes often. I only showed the first few line. Seriously... we cant loop 6 times the code?
Ok use the <apex:repeat tag.

Or better yet, try apex:dataTable which iterates over a collection AND creates a table for you.


Also, don't do this:


<img id="theImage" src="https://na1.salesforce.com/servlet/servlet.FileDownload?file=01530000000mvyc" />


 Instead, do this:



<apex:image value="{!URLFOR($Action.Document.Download, docid)}"/>


 Where 'docid' is from your iteration. This ensures your image won't break if moved to another environment (e.g. na1 becomes na8) or if salesforce.com changes the endpoint for downloading files.


Finally, pasting record IDs into a page makes the page useless in other environments.  Any attempt to migrate such a page to an org without the same data (including the IDs) will break it and it will have to be fixed up manually.  Not to mention there is nothing preventing the doc from being deleted which would also break the link.  "hard coded" references like this are best left to Static Resources. 


Check out the Visualforce Developer Guide for more info on Static Resources, apex:dataTable, etc.