Jul 7, 2011

Binding Values of Map on Visualforce Page

I was totally messed up with this and thanks to Bob Buzzard for providing me the solution to it.


What exactly the problem is? I was trying to display values of Map on visualforce page. This code snippet will help you to understand more.
<apex:repeat value="{!MyMap}" var="M">
 <apex:repeat value="{!MyMap[M]}" var="temp">
  <apex:outputLabel value="{!temp.Test_Curr__c}"/>
 </apex:repeat>
</apex:repeat>
"MyMap" is in my controller having list of account (Map<String , List<Account>>). I just want to bind the currency field value of account with outPutField like this :
<apex:repeat value="{!MyMap}" var="M">
 <apex:repeat value="{!MyMap[M]}" var="temp">
         <apex:outputField value="{!temp.Test_Curr__c}"/>
 </apex:repeat>
</apex:repeat>
But compiler gifted me this : "Error: Could not resolve the entity from <apex:outputField> value binding '{!temp.Test_Curr__c}'. outputField can only be used with SObject fields."


Now it is mandatory for me to bind the value with outPutField as I want the formatting of currency field on my visualforce page.


Using outPutLabel doesn't provide formatting either :
<apex:repeat value="{!MyMap}" var="M">
 <apex:repeat value="{!MyMap[M]}" var="temp">
  <apex:outputLabel value="{!temp.Test_Curr__c}"/>
 </apex:repeat>
</apex:repeat>
So finally I need the Community help, and trust me it is the best place to get your answers quickly.


Workaround for this is using <apex:column> as it provides the sObject field behaviour. So my final code looks something like this :
<apex:pageBlockTable value="{!MyMap}" var="M">
 <apex:repeat value="{!MyMap[M]}" var="temp">
  <apex:column value="{!temp.Test_Curr__c}" />
 </apex:repeat>
</apex:pageBlockTable>
For reference click here to get community post.


Hope this flaw will be fixed soon as there might be some cases where we do not want to use pageBlockTabel.


Cheers

1 comment:

  1. I have joined your feed and sit up for searching for more of your great post.
    Additionally, I have shared your web site in my social networks.
    hotmail sign up login

    ReplyDelete