I'm trying to iterate over a map of custom apex objects in Visualforce and am unsure how to syntaxicly express it to work.
Scenario that works: map of custom objects
controller:
public Map<Id,cusObj__c> DummyRecordMap{get;set;}
VF
<apex:pageBlockTable value="{!DummyRecordMap}" var="rId" >
<apex:column >
<apex:facet name="header">Record Name</apex:facet>
<apex:outputfield value="{!DummyRecordMap[rId].Name}"/>
</apex:column>
</apex:pageBlockTable>
Scenario that does not work: map of apex wrapper objects - upd:actually this does work, the flaw was mine and unrelated.
Now, in order to store some extra data per each record in memory I want to use a wrapper apex object as I believe is best practice in such cases. I have done this successfully with List in visualforce in the past, but trying to do this with a map it gives unexpected results. Am I doing something wrong ?
controller:
public Map<Id,DummyWrapper> DummyWrapperMap{get;set;}
//wrapper class
public class DummyWrapper{
public boolean extraField {get;set;}
public cusObj__c cusObj{get;set;}
public DummyWrapper(cusObj__c cO){
extraField = true;
cusObj = cO;
}
}
Visualforce:
<apex:pageBlockTable value="{!DummyWrapperMap}" var="rId" >
<apex:column >
<apex:facet name="header">Record Name</apex:facet>
// --> this does not work like I would have expected <--
<apex:outputfield value="{!DummyWrapperMap[rId].cusObj.Name}"/>
</apex:column>
</apex:pageBlockTable>
This does not give errors but displays default values for the correct datatype of the field in the custom object that I try to display. The Name field displays an empty string, a date field the data of today and a decimal displays 0. These fields are unknown to the wrapperobject so the apex:outputfields I try to display them do show the correct datatype, but do not reflect the actual data.
Any ideas ?
(I know that as work around I can tunnel the custom object fields through wrapper object properties, but .. not what I'd prefer to do)
Update: answer to comments
public void buildDummyWrappers(){
if(DummyRecordMap != null){
Account ac = [select Id,name from account limit 1]; //TESTING
DummyWrapperMap = new Map<id,Dummyrapper>();
for(cusObj__c cO:DummyRecordMap.values()){
dummyWrapperMap.put(c0.id,new DummyWrapper(co,ac));
}
}
}
//wrapper class
public class DummyWrapper{
public boolean extraField {get;set;}
public cusObj__c cusObj{get;set;}
public Account Acc{get;set;} //TESTING
public DummyWrapper(cusObj__c cO, Account ac){
extraField = true;
cusObj = cO;
Acc = ac;
}
}
<apex:repeat value="{!DummyWrapperMap}" var="rId">
// this works, gives the records Ids (as it should)
<apex:outputText value="{! rId}"/>
//this also works fine
<apex:outputText value="{! DummyWrapperMap[rId].extraField}"/>
//this does not display anything
<apex:outputText value="{! DummyWrapperMap[rId].cusObj.Name}"/><br />
//This does work !
<apex:outputText value="{! DummyWrapperMap[rId].Acc.Name}"/>
</apex:repeat>
Final update: The problem was in fact in my code. Got to use this.Field = field instead of assuming the compiler will know the difference without this. Case insensitivity.