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
Joseph BauerJoseph 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:
 
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)
Nayana KNayana K
Error is because of keymap[0] is a list and you are trying to display it as text...
<apex:repeat value="{!keymap[0]}" var="innerLstElement">
<apex:outputText value="{!innerLstElement}"/>
</apex:repeat>
Joseph BauerJoseph Bauer

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?

Joseph BauerJoseph Bauer
I can loop through but I need to reference individual subscripts of the list like line 5 below (but this causes the expected text, received number error): This is what causes the problem: list[0]
<apex:page controller="testMapController">
<apex:repeat value="{!DemoMap}" var="key" >
    <apex:repeat value="{!DemoMap[key]}" var="keyvalue" >
        <apex:repeat value="{!keyvalue}" var="list">
            <apex:panelgroup rendered="{!IF(list[0] == list[1]), true, false}">
            <apex:outputText value="{!keyvalue}" />
            </apex:panelgroup>
        </apex:repeat>
        <br/>
   </apex:repeat>
</apex:repeat>
</apex:page>
Ekta Gupta 11Ekta Gupta 11
Hello Joseph,

'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!
Joseph BauerJoseph Bauer

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?

Ekta Gupta 11Ekta Gupta 11
Do you want something like this:
<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

 
Joseph BauerJoseph Bauer
No because there are 15 strings in the last list and I need to use all the strings in one line of code like:

new JS.Task({!item[0]}, {!item[1]},...{!item[14]});
Joseph BauerJoseph Bauer
And I really need access to the individual subscripts because there is another map i'm using that uses on of the subscripts as the key to the map. I've tried using JS with it but to no avail. I can store the values in javascript but can't use javascript variables as the key for the apex map.
Ekta Gupta 11Ekta Gupta 11
Not sure if i understood you correctly.
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.