You need to sign in to do that
Don't have an account?

Dynamic Get
Hey all,
Would it be possible to do something like this:
public map<string,integer> field1 = new map<string,integer>(); public map<string,integer> field2 = new map<string,integer>(); public test3(ApexPages.StandardController controller) { this.field1.put('a',1); this.field2.put('b',2); } public integer getx(string x){ return field2.get(x); }
I'm just looking to be able to have something on the VF side like {!x[a]} to return 1. Possible?
Thanks!
If you use dynamic visualforce bindings, you should be able to access a value from the map directly by its key without recourse to a getter.
You'll need to make the maps properties, but aside from that there's not much to change:
Controller:
and page:
There's more detail and example code at:
http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#CSHID=pages_dynamic_vf_maps_lists.htm|StartTopic=Content%2Fpages_dynamic_vf_maps_lists.htm|SkinName=webhelp
There's also a blog post of mine around this at:
http://bobbuzzard.blogspot.com/2011/03/visualforce-dynamic-map-bindings.html
To the rescue again! Thanks Bob for the code and the links. I've been trying to solve a problem with how to determine when to render a field on a layout, based on the values of two other fields. This should help greatly!
Would it be possible to do something like this then? I'm looking to be a little more dynamic with rendering fields on my layout.
I updated the code above to what would compile, found below, but am receiving:
Error: Unknown property 'Photo__cStandardController.render'
This is because your usage of render indicates to the page "compiler" that it is a map that is public with a public getter and setter. You are attempting to pass a parameter to a getter, which is not allowed in Visualforce.