You need to sign in to do that
Don't have an account?
Joseph Bauer
Can an apex:repeat variable value be list of list of string?
I have a map<list<list<string>>> variable that I need to iterate over in visualforce. Here is my code:
Here is the error I am receiving when trying to save the visualforce page:
Incorrect parameter type for subscript. Expected Text, received Number (even though its a list of lists and should be a number in the subscript)
public class testMapController { public Map<String, List<List<String>>> getDemoMap(){ Map<String, List<List<String>>> demoMap = new Map<String, List<List<String>>>(); List<String> testList = new List<String>(); testList.add('test'); testList.add('testing'); List<List<String>> listOfList = new List<List<String>>(); listOfList.add(testList); List<String> testList2 = new List<String>(); testList2.add('test2'); testList2.add('testing2'); listOfList.add(testList2); demoMap.put('first', listOfList); demoMap.put('second', listOfList); return demoMap; } } <apex:page controller="testMapController"> <apex:repeat value="{!DemoMap}" var="key" > <apex:repeat value="{!DemoMap[key]}" var="keyvalue" > <apex:outputText value="{!keyvalue[0]}" /> <br/> </apex:repeat> </apex:repeat> </apex:page>
Here is the error I am receiving when trying to save the visualforce page:
Incorrect parameter type for subscript. Expected Text, received Number (even though its a list of lists and should be a number in the subscript)
<apex:repeat value="{!keymap[0]}" var="innerLstElement">
<apex:outputText value="{!innerLstElement}"/>
</apex:repeat>
Neither of these work:
<script>console.log("{!keyvalue[0][0]}");</script>
<apex:outputText value="{!keyvalue[0][0]}" />
How would I loop through the list of list?
'keyvalue' is again the list, So you have to again iterate.
Try this code:
<apex:page controller="testMapController">
<apex:repeat value="{!DemoMap}" var="key" >
<apex:repeat value="{!DemoMap[key]}" var="keyvalue" >
<apex:outputText value="{!keyvalue}" />
<br/>
</apex:repeat>
</apex:repeat>
</apex:page>
Output will look like:
[test, testing]
[test2, testing2]
[test, testing]
[test2, testing2]
If you want to display all the result then use this code:
<apex:page controller="testMapController">
<apex:repeat value="{!DemoMap}" var="key" >
<apex:repeat value="{!DemoMap[key]}" var="keyvalue" >
<apex:repeat value="{!keyvalue}" var="Count" >
<apex:outputText value="{!Count}" />
<br/>
</apex:repeat>
</apex:repeat>
</apex:repeat>
</apex:page>
In this case your output should be like this:
test
testing
test2
testing2
test
testing
test2
testing2
let me know if this helps.
Good day!
But I don't want to iterate in the last list. I just want to reference all the indexes. Basically what I'm doing is creating an object in Javascript so I need the last list to do this:
<script>
var task = new JSGantt.tasks("{!list[0]}", "{!list[1]}");
</script>
Bit using the subscript notation on the list doesn't work for some reason. How can I reference without iterating throug hall of the items in the list?
<apex:page controller="testMapController">
<apex:repeat value="{!DemoMap}" var="key" >
<apex:variable value="{!-1}" var="count"/>
<apex:repeat value="{!DemoMap[key]}" var="keyvalue" >
<apex:variable var="count" value="{!count+1}" />
<apex:panelgroup rendered="{!IF(DemoMap[key][0] == DemoMap[key][count], true, false)}">
<apex:outputText value="{!keyvalue}" />
</apex:panelgroup>
<br/>
</apex:repeat>
</apex:repeat>
</apex:page>
Output:
[test, testing]
[test, testing]
It will check the first element with the current element of the list and then will display it
new JS.Task({!item[0]}, {!item[1]},...{!item[14]});
You might need to use <apex:variable> for iteration in you repeat tag '<apex:repeat value="{!keyvalue}" var="list">' this will help to get only the last list
Now to access the individual strings of only last list u have to use another apex:repeat to get the strings from the list.
Basically you can use subscripts like list[0] in VF page.. U have to apex:repeat again to get the data from list.
Or else you might have to think of diff data model.