+ Start a Discussion
subhajit13subhajit13 

Issue with apex:attribute type="map"

I am having issue to assign a map from<apex:attribute type="map" assignedTo={!method}

 

Getting the below error message:

 Error: Type mismatch for <apex:attribute assignTo>. Value binding to a property of type MAP<Object,Object> is required, property specified is of type MAP<String,String>.

 

Below is the code snipet I am using:

VF Component:

    <apex:attribute name="leftOptions" description="Map for left Picklist" type="map" required="true" assignTo="{!test}"/>

Definition in Controller:

public Map<String,String> test {get;set;}

 

Note: the same errot comes for below definitions as well -

public Map<Account,Contact> test {get;set;}

public Map<sObject,sObject> test {get;set;}

 

Please let me know anyone need more information to help. Thanks in advance.

 

 

Sridhar BonagiriSridhar Bonagiri

Hi,

 

I think you cannot define a map with object types. Please go through the below URL for detail descrption on maps.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_collections_maps.htm

 

and for <apex:attribute pl. follow the below URL.

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_attribute.htm

 

Regards,

Sridhar Bonagiri

subhajit13subhajit13

Hi Sridhar, thanks for your reply. 

 

I think I am missing something here, you mean to say I cannot define a Map<String, String>()?

Also, to give you litle more info - 

From my code snipet - 

If I just remove RED marked, both page and controller gets saved without any issue -

Page:

<apex:attribute name="leftOptions" description="Map for left Picklist" type="map" required="true" assignTo="{!test}"/>
Definition in Controller:
public Map<String,String> test {get;set;}

 

Could you please help me with a simple example of apex:attribute type="map" where you are assigning the map into controller variable? (an example for below in other words!):

 

typeString
The Apex data type of the attribute. If using the assignTo attribute to assign the value of this attribute to a controller class variable, the value for type must match the data type of the class variable. Only the following data types are allowed as values for the type attribute:
  • Maps, specified using type="map". You don't need to specify the map's specific data type.

 

Thanks again for your time and help. Really appriciate!

espostorespostor

Bump.

 

It is apparent that the assignTo parameter of apex:attribute does not support maps, period. 

 

Even when the map property in the Apex controller is defined as a Map<Object,Object> it still doesn't work. What's worse is that the error message displayed is:

 

"Save error: Type mismatch for <apex:attribute assignTo>. Value binding to a property of type MAP<Object,Object> is required, property specified (testOptions) is of type MAP<ANY,ANY>."

 

Besides being a clear defect, this error message is incredibly silly.

songlansonglan

I got the same error "Save error: Type mismatch for <apex:attribute assignTo>. Value binding to a property of type MAP<Object,Object> is required, property specified (testOptions) is of type MAP<ANY,ANY>." when trying to assign a map to a variable of controller using apex:attribute. It is still not supported for the Summer 13. Seems we can only use the map to display information not to pass it to the controller