2

I have a problem with making a dynamic table component that displays selected sObject fields with specified header values. The very first idea was to supply the component with an apex:attrubite of type Map, containing a key-value pairs for column headerValue and sObject field name correspondingly. Then use apex:repeat to iterate through the collection and add appropriate headers and apex:outputField just like that:

Component

<apex:attribute name="collection" description="..." type="sObject[]" assignTo="{!sObjectCollection}"/>
<apex:attribute name="fields" description="..." type="Map<String,String>" assignTo="{!fieldsMap}"/>

<apex:pageBlockTable value="{!sObjectsCollection}" var="collectionItem">
    <apex:repeat value="{!fieldsMap.keySet()}" var="key">
        <apex:column headerValue="{!key}">
            <apex:outputField value="{!collectionItem.get(fieldsMap.get(key)}"/>
        </apex:column>
    </apex:repeat>
</apex:pageBlockTable>

Controller

public List<sObject> sObjectsCollection{ get; set; }
public Map<String, String> fieldsMap { get; set; }

But I get the error: Unsupported type Map<String,String> encountered. I'm sure there is some better approach to get desired result.


I have also tried to get the headerValues from one String and the field names from another but then I don't know how to assign a proper headerValue to specific field name. Any ideas?

1
  • I believe that it is a bug in salesforce and you cannot pass Map as attribute to custom component. Try create your own class that will wrap Map. Example for that, you can find in this topic: salesforce.stackexchange.com/questions/32554/…
    – mischczu
    Commented Jul 26, 2015 at 21:49

2 Answers 2

0

from the Visualforce Developer’s Guide

Maps, specified using type="map". You don't need to specify the map's specific data type.

Have you tried this ?

1
  • Yes, I have tried this as well. I have found a better approach to make this dynamic table and I will update my post as soon as I finish implementing it. Commented Jul 29, 2015 at 16:56
0

Accepting maps in Components is unfortunately unsupported. Setting the type to simply Map will not cause the Component to actually accept Maps so we can just as well consider that option to be non-existent.

You'll have to create a wrapper class around your Map, then use that wrapper class as the Type in your apex:attribute and pass your map around like that.

You must log in to answer this question.

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