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
MiddhaMiddha 

Visualforce Dynamic Binding with Custom Components

Hi All,

 

I am trying to access values of a map in my class on the VF page using Dynamic Binding. 

 

{!mymap['firstname']}

 

This works fine but now if I try to pass this as an attribute in one of the custom VF components it throws an error:

 

<c:mycomp fname="{!mymap['firstname']}"/>

 

Error thrown: Unknown property 'MapValue.firstname'.

 

any thoughts?

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

It might be a bug of some sort. Try using an apex:variable, assign mymap['firstname'] to that variable, then use that variable in the custom component's attribute. Something like this:

 

<apex:variable name="fname" value="{!mymap['firstname']}"/>
<c:mycomp fname="{!fname}"/>

I know there's a few bugs related to collections not working correctly in all cases, and this might be one of them. The variable technique should work.

All Answers

sfdcfoxsfdcfox

It might be a bug of some sort. Try using an apex:variable, assign mymap['firstname'] to that variable, then use that variable in the custom component's attribute. Something like this:

 

<apex:variable name="fname" value="{!mymap['firstname']}"/>
<c:mycomp fname="{!fname}"/>

I know there's a few bugs related to collections not working correctly in all cases, and this might be one of them. The variable technique should work.

This was selected as the best answer
MiddhaMiddha

The workaround worked. Thank you.

May be this is an issue. One small fix for who's using this.

 

<apex:variable var="fname" value="{!mymap['firstname']}"/>
<c:mycomp fname="{!fname}"/>