You need to sign in to do that
Don't have an account?
Binding values of Map on VF page
I was browsing on my problem in this community and saw many faced similar issue but not found any exact solution .
Problem is simple..I've a map like this
Map<id,integer> MapAppstoRating = new Map<id,integer>();
Controller populates this Map. Now what I want is to show values of this map in my VF page. Other thing is..I want to display name of the associated custom object 'record Name' instead of 'record ID' and integer value.
Now thing is, I was able to populate id with integer value with something like :
<apex:pageblockTable var="c" value="{!MapAppstoRating }" >
<apex:repeat value="{!MapAppstoRating [c]}" var="temp">
<apex:column value="{!c}" />
</apex:repeat>
<apex:repeat value="{!MapAppstoRating [c]}" var="temp">
<apex:column value="{!temp}" />
</apex:repeat>
</apex:pageblockTable>
But it has 2 problems..
Firstly..it is populating just first element of associated map. Other rows are not getting populated. But major problem is..I 've to populate name
instead of IDs... Is that possible somehow. or I need to change my map to get names instead of ids?( changing that will be more cumbersome for me )
thanks for help!
Alright, I think the below code will work for you:
Use finalMapAppstoRating in your visualforce page. I am pretty mych sure that it should work.
Regards,
Lakshman
All Answers
This could help you somewhere
http://boards.developerforce.com/t5/Apex-Code-Development/Error-OutputField-can-only-be-used-with-SObject-fields/td-p/302505
thanks for your reply....but I've already seen that post before posting my question. It actually didn't answer my question. I've to print names associated with Ids which is the problem. My basic question : is that possible or not or I've to change my maps to reach solution ?
Thanks !
Please try as below and let me know if it works:
Regards,
Lakshman
Hi Lakhsman, Thanks for reply. But it is giving problem
Actually, let me give little more detail,
During the process of populating the given map(i.e. MapAppstoRating) , I need to get existing value from it. and then add new value in it. Giving dummy example below :
For(review__c rv : allrevs)
{
ratingsum = MapAppstoRating.get(rv.Job_Application__c);
ratingsum = ratingsum + Integer.valueOf(rv.rating__c);
MapAppstoRating.put(rv.Job_Application__c,ratingsum );
}
Now first line inside 'for' loop is working only , if map has 'id' as 'key' . Whatever else(sobject, actual object name etc) I'm using, it is not working.
But while printing values of Map, I need to print names..instead of Id...(here name of job_application__c object)
Any help on this is appreciated!
One quick question, How are you getting this: rv.Job_Application__c, is it through SOQL? If yes can you try doing it like: rv.Job_Application__r.Name. But doing so we will need unique names.
Regards,
Lakshman
Alright, I think the below code will work for you:
Use finalMapAppstoRating in your visualforce page. I am pretty mych sure that it should work.
Regards,
Lakshman
Thanks a lot for you help Lakshman , this actually worked for me :)
I am glad that it worked for you :)
Regards,
Lakshman