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
Deepak Singh 116Deepak Singh 116 

​​​​​​​I am unable to print array return by controller on VF page

Hi,
I am unable to print array return by controller on VF page:-
Controller:-
public with sharing class generateStringArray {
    public list<String> generateStringArray{ get; set; }
    public static list<string> getgenerateStringArray(){
        Integer n=10;    
        list<string> myarray=new list<string>();
        for(integer i=0;i<=n;i++){
            myarray.add('Test'+i);
        }
        return myarray;
    } 
}

VF page:-
<apex:page Controller="generateStringArray" showHeader="true" sidebar="false">
    <h1>List</h1>
    
        <apex:repeat value="{!generateStringArray}" var="string" id="theRepeat">
        <apex:outputText value="{!string}" id="theValue"/><br/>
        </apex:repeat>

  
</apex:page>

 
Best Answer chosen by Deepak Singh 116
Raj VakatiRaj Vakati
Use this
 
public with sharing class generateStringArray {
    public static list<string> getGenerateStringArray(){
        Integer n=10;    
        list<string> myarray=new list<string>();
        for(integer i=0;i<=n;i++){
            myarray.add('Test'+i);
        }
        return myarray;
    } 
}
 
<apex:page Controller="generateStringArray" showHeader="true" sidebar="false">
    <h1>List</h1>
    
        <apex:repeat value="{!generateStringArray}" var="string" id="theRepeat">
        <apex:outputText value="{!string}" id="theValue"/><br/>
        </apex:repeat>

  
</apex:page>

 

All Answers

Raj VakatiRaj Vakati
Use this
 
public with sharing class generateStringArray {
    public static list<string> getGenerateStringArray(){
        Integer n=10;    
        list<string> myarray=new list<string>();
        for(integer i=0;i<=n;i++){
            myarray.add('Test'+i);
        }
        return myarray;
    } 
}
 
<apex:page Controller="generateStringArray" showHeader="true" sidebar="false">
    <h1>List</h1>
    
        <apex:repeat value="{!generateStringArray}" var="string" id="theRepeat">
        <apex:outputText value="{!string}" id="theValue"/><br/>
        </apex:repeat>

  
</apex:page>

 
This was selected as the best answer
Raj VakatiRaj Vakati
You dnt set ant value in the generateStringArray variable that why you are not seeing any output 
Deepak Singh 116Deepak Singh 116
Thanks Raj,
I have one more query . I dont want to set the value of "n" in controller , i want this value to be entered by user from VF page take as a parameter in the  getGenerateStringArray. or is there any other workaround for the same.

Regards,
Deepak