3

Hi I've been trying to figure this out on my own but haven't been able to get it to work. I have a map of a map Map<string,Map<String, list<Accounts>>> mapToAccounts . The inner key is a string which represents an url while the outer key is just the name of the site. I am attempting to create a hyperlink which shows the name of the site and the destination is the inner key(which is an url). Something like this <apex:outputLink value="{!theAccountsOfSitesAndMaps[innerkey]}">{!outerKey}</apex:outputLink> . Any suggestions will be great.

public Map<String,Map<String, list<Accounts>>> getTheAccountsOfSitesAndMaps() {         
    return maptoaccounts;
    }    

Just updated below with suggestions from sfdcfox and Eric but receiving a new error: Error is in expression '{!TheAccountsOfSitesAndMaps[outerKey][innerKey]}' in component in page

 <apex:pageBlock >
    <apex:repeat value="{!TheAccountsOfSitesAndMaps}" var="outerKey">
        <apex:pageBlockTable value="{!TheAccountsOfSitesAndMaps}[outerKey]" var="innerKey">        
          <apex:repeat value="{!TheAccountsOfSitesAndMaps[outerKey][innerKey]}" var="account">
              <apex:column headervalue="Sites" />   
          <apex:outputLink value="{!innerKey}">{!outerKey}</apex:outputLink>            

          </apex:repeat>
        </apex:pageBlockTable>
    </apex:repeat>
</apex:pageBlock>
2
  • Is it important in your example markup that you've got two maps one called TheAccountsOfSitesAndMaps and one called mapToAccounts? Do you really have two separate map instances?
    – Mark Pond
    Commented Dec 31, 2013 at 6:05
  • Hi Mark, I apologize for not providing enough information. I'am actually returning the map in a method called TheAccountsOfSitesAndMaps. Commented Dec 31, 2013 at 18:04

2 Answers 2

8
<apex:repeat value="{!mapToAccounts}" var="outerKey">
    <apex:repeat value="{!mapToAccounts[outerKey]}" var="innerKey">
        <apex:repeat value="{!mapToAccounts[outerKey][innerKey]}" var="account">
            <apex:outputLink value="{!innerKey}">
                {!outerKey}
            </apex:outputLink>
        </apex:repeat>
    </apex:repeat>
</apex:repeat>

Of course, feel free to use tables (apex:dataTable, apex:pageBlockTable, etc) as appropriate, and any other dressing you need.

3
  • Thanks sfdcfox. Your answer works with apex repeat but I'm having troubles getting it to work with apex pageblocktable. Could you offer any help? Commented Dec 30, 2013 at 19:31
  • There is no difference between an <apex:repeat /> and an <apex:pageBlockTable /> aside from the fact that one renders anything you wish to build with it and the other renders an HTML table with the Salesforce pageblock table style and structure. Can you demonstrate a specific problem with the <apex:pageBlockTable /> that was working well with the <apex:repeat /> tag?
    – Mark Pond
    Commented Dec 31, 2013 at 6:16
  • @sw6-KTBFFH Within a pageBlockTable, all elements must be contained in a apex:column element in order to be displayed. Other than that, there is no functional difference.
    – sfdcfox
    Commented Dec 31, 2013 at 14:15
1

Ok. Seems the repeat does not work well inside a pageblock table.

This however does work:

CLASS

    public class vfpagetest{

public Map<String,Map<String,String>> tmp {get;set;}
public String s {get;set;}

    public vfpagetest(){
    s = 'TEST';
        tmp = New Map<String,Map<String,String>>();

        tmp.put('1',New Map<String,String>{'A'=>'3','B'=>'4'});
        tmp.put('2',New Map<String,String>{'C'=>'5','D'=>'6'});
    system.debug(logginglevel.error,tmp);
    }


}

VF PAGE

<apex:page controller="vfpagetest">

<apex:pageBlock >

<table>
    <th>test</th>

    <apex:repeat value="{!tmp}" var="outerKey">
    <tr>
    <apex:repeat value="{!tmp[outerKey]}" var="innerKey">
    <td>{!outerKey} - {!innerKey}</td>
    <td>{!tmp[outerKey][innerKey]}</td>
    </apex:repeat>
    </tr>
    </apex:repeat>
   </table>


</apex:pageBlock>


</apex:page>
2
  • Hi Eric I apologize if it seems I have not been responding or giving any feedback- I'm in the process of moving to a new house and been running around all day. Like you may have seen yourself the apex repeat does not work entirely well inside the pageblocktable. I will implement your new solution as soon as I get a bit of work time. Thank you. Commented Jan 1, 2014 at 2:25
  • No worries at all. Just trying to help. Hopefully SFDCFOX will chime in here and help with a more elegant solution. I did not have time to work anything but this mock up up.
    – Eric
    Commented Jan 1, 2014 at 6:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .