function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
davidjbbdavidjbb 

Apex Repeat

Hello,

 

The example provided by Salesforce:

 

<!-- Page: --> 
    

<apex:page controller="repeatCon" id="thePage">

    <apex:repeat value="{!strings}" var="string" id="theRepeat">

        <apex:outputText value="{!string}" id="theValue"/><br/>

    </apex:repeat>

</apex:page>

			

/*** Controller: ***/ 
    

public class repeatCon {



    public String[] getStrings() {

        return new String[]{'ONE','TWO','THREE'};

    }

}

 Displays 

 

<span id="thePage:theRepeat:0:theValue">ONE</span><br/>

<span id="thePage:theRepeat:1:theValue">TWO</span><br/>

<span id="thePage:theRepeat:2:theValue">THREE</span><br/>

 

How can I code it in a way it'll show the following:


ONE

TWO

THREE

 

Instead of

 

<span id="thePage:theRepeat:0:theValue">ONE</span><br/>

 

I plan on doing an export on the VF page using contentType and will display the following

 

<salorder>
"sForce",,,"The Landmark @ One Market",,"San Francisco","CA","94087","US"
"1","00004757" ,"7-9-2012","7-9-2012","0.00","0.00" 
"","1.0000","0.0000","0.00" Fieldworker Rate
</salorder>

 

I should be able to display the following above in the same format, spacing etc. The above would be considered one record so there will be multiple <salorder> </salorder> based off my data construction.

S91084S91084

You can also you HTML <table> between <apex:repeat> and display the list the way you like.

davidjbbdavidjbb

I plan on doing an export on the VF page using contentType

I want it in a text file, so I don't think the HTML table will help. I just want to display the values .

 

<salorder>
"sForce",,,"The Landmark @ One Market",,"San Francisco","CA","94087","US"
"1","00004757" ,"7-9-2012","7-9-2012","0.00","0.00"
"","1.0000","0.0000","0.00" Fieldworker Rate
</salorder>

 

I should be able to display the following above in the same format, spacing etc. The above would be considered one record.

 

rklaassenrklaassen

Try something like this:

<apex:page controller="repeatCon" id="thePage">
    <apex:repeat value="{!strings}" var="string" id="theRepeat">
        "{!string}"
    </apex:repeat>
</apex:page>


/*** Controller: ***/ 
public class repeatCon {
    public String[] getStrings() {
        return new String[]{'ONE','TWO','THREE'};
    }
}

 

davidjbbdavidjbb

Instead of 'One','Two','Three'.

 

Is it possible to insert a List?

 

/*** Controller: ***/ 
public class repeatCon {
    public String[] getStrings() {
        return new String[]{'ONE','TWO','THREE'};
    }
}
JHayes SDJHayes SD

You could always ditch the apex:repeat element and create your string in controller code:

 

    public String getListAsCsv() {
    	
    	// Creating your list..
    	String[] vals = new String[3];
    	vals[0] = 'ONE';
    	vals[1] = 'TWO';
    	vals[2] = 'THREE';
    	
    	// Convert to CSV...
    	return convertListToCsv(vals);    	
    }
    
    private String convertListToCsv(List<String> vals) {
    	
    	String listAsCsv = '';
    		
    	// Convert to CSV, need to add a little more logic if your field values will contain double quotes.
    	for (String s : vals) {
    		
    		listAsCsv += '"' + s + '",';
    	}    	
    	
    	// Remove last character
    	listAsCsv = listAsCsv.substring(0, listAsCsv.length() - 1);
    	    	
    	return listAsCsv;
    	
    }

 

 

Then in the VF page all you need to do is reference {!listAsCsv}.

 

Regards, jh