You need to sign in to do that
Don't have an account?
mritz
The problem is that when i save this visualforce page code after saving apex code i am getting error:
Subscript is invalid because list is empty
Error: Subscript is invalid because list is empty
Apex Code: public class myClass{ public list<String> myValues{get;set;} public string outTxt{get;set;} public myClass(){ outTxt='here-> '; myValues=new list<String>(); } public void concatenate(){ for(integer i=0;i<4; i++) outTxt+=myValues[i]+'\n'; } } VisualForce Page Code: <apex:page controller="myClass"> <apex:form > <table> <tr> <td>Value1:</td> <td><apex:inputtext value="{!myValues[0]}" id="val1"/></td> </tr> <tr> <td>Value2:</td> <td><apex:inputtext value="{!myValues[1]}" id="val2"/></td> </tr> <tr> <td>Value3:</td> <td><apex:inputtext value="{!myValues[2]}" id="val3"/></td> </tr> <tr> <td>Value4:</td> <td><apex:inputtext value="{!myValues[3]}" id="val4"/></td> </tr> <tr> <td><apex:commandButton value="Concatenate" action="{!concatenate}"> <apex:ActionSupport event="onclick" rerender="txt"/> </apex:commandButton> </td> </tr> </table> <apex:outputText id="txt">{!outTxt}</apex:outputText> </apex:form> </apex:page>
The problem is that when i save this visualforce page code after saving apex code i am getting error:
Subscript is invalid because list is empty
Please replace your class with below code it will work .
Thanks
Manoj
All Answers
Currently your list is empty .What actually you want do display in your page ?
Please replace your class with below code it will work .
Thanks
Manoj
myValues=new list<String>{'','','',''};
What in case i have 10s of such fields, do i need to have equal no of null strings?
or is there any better approach.
Yes you need to instantiate the list with 10 number of null string . Else you can create different different variable for each field and do addition in method .But it will be selected as best approach based on your requirement .
I modified the constructor a bit and its like: