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?

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 ?

  • 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. – Paweł Hajduk Jul 29 '15 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.