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
NakataNakata 

Can Map collection be Apex:Repeat tag 's value ?

Good day,

 

Can i know if Apex:Repeat tag's value able hold Map instead of List ?

 

 

VF page
------------
<apex:repeat value="{!partnerFieldList}" var="field">

<apex:variable var="currentLabel" value="{!$Label.first_name}" rendered="{field.containsKey('First_Name__c')}"/>


Controller
-----------
public Map<String,Boolean> partnerFieldList = new Map<String,Boolean>{
'First_Name__c' => TRUE

};

 

public Map<String,Boolean> getPartnerFieldList(){
return partnerFieldList;

 

 

 I would like to rendered the 'firstname' variable if the field are calling, but i get "Unsupported type common.apex.runtime.impl.MapValue encountered."error when i run the apex page

 

Thank you !

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Rather than attempting to use a Map as the backing value for the repeat, you would define a subclass encapsulating all the information required of an entry in the Map, and return a List of instances of the subclass.

 

E.g. 

 

 

-- in controller 

  

public List<PartnerFields> partnerFieldList = new List<PartnerFields>();

public List<PartnerFields> getPartnerFieldList()

{

PartnerFields pf=new PartnerFields();

pf.hasFirstName=true;

partnerFieldList.add(pf);

return partnerFieldList;

}

 

public class PartnerFields

{

public Boolean hasFirstName {get; set;}

}

 

-- in VF page

 

<apex:repeat value="{!partnerFieldList}" var="field">

<apex:variable var="currentLabel" value="{!$Label.first_name}" rendered="{!field.hasFirstName}"/>

 

 

 

 

 

 

 

 

Message Edited by bob_buzzard on 11-10-2009 05:08 AM

All Answers

NaishadhNaishadh
You need to use subclass logic for achieving the same.
NakataNakata

Hi ,

 

Do you mind to provide me some sample what you means by subclass logic ?

 

Thank you !

bob_buzzardbob_buzzard

Rather than attempting to use a Map as the backing value for the repeat, you would define a subclass encapsulating all the information required of an entry in the Map, and return a List of instances of the subclass.

 

E.g. 

 

 

-- in controller 

  

public List<PartnerFields> partnerFieldList = new List<PartnerFields>();

public List<PartnerFields> getPartnerFieldList()

{

PartnerFields pf=new PartnerFields();

pf.hasFirstName=true;

partnerFieldList.add(pf);

return partnerFieldList;

}

 

public class PartnerFields

{

public Boolean hasFirstName {get; set;}

}

 

-- in VF page

 

<apex:repeat value="{!partnerFieldList}" var="field">

<apex:variable var="currentLabel" value="{!$Label.first_name}" rendered="{!field.hasFirstName}"/>

 

 

 

 

 

 

 

 

Message Edited by bob_buzzard on 11-10-2009 05:08 AM
This was selected as the best answer
NakataNakata
Thank you Sir !
dke01dke01

This is pathetic.  Yet add another cheap work around to the big list of things that should just work out of the box.

 

Please vote to fix this here http://sites.force.com/ideaexchange/ideaView?c=09a30000000D9xt&id=08730000000IIn5AAG