You need to sign in to do that
Don't have an account?
MG Consulting
inputField Dynamic Binding?
Hi,
Quick question, the answer to which I am guessing is currently no but someday yes:
<apex:inputField value="{!Contact.Name}"/> <!-- Static -->
<apex:inputField value="{!Contact.get('Name')}"/> <!-- Dynamic -->
Is there anyway currently to do something like the Dynamic example above, so that the field my be varied at runtime?
It would certainly make my life a whole lot easier...
Thanks a lot,
Mike
VisualForce doesn't support the Get(), but what you could do is use Dynamic DML in your Apex so that the query retrieves every field in the object, even custom fields added after the code was deployed. Then your user could edit the VisualForce to display whatever fields they wanted. It's not as slick as controlling the fields in a table, but it does let your user get away with making changes without having to do them in a Sandbox and deploy.
Alternatively, you could create a wrapper class for your object that has generic methods for the fields - field1, field2, field3, etc. The Apex could read your customization object to retrieve the field names and then assign them to field1, field2, field3, etc. That would enable the user to completely control what appears in your VF page without them having to actually edit the VF page contents.
Mike
Thanks for the suggestions, unfortunately, I definitely can't have them editing the Visualforce :(
But, I'm actually currently working on a design similar to your alternative suggestion.
The problem is, you loose all the magic of the inputField, i.e. the way it just displays any field type optimally. For starters, this means that I'm going to have to roll my own date picker, among other not so fun things. It sucks to loose it, but I guess I gotta do what I gotta do at this point.
Hadn't thought about losing the inputField formatting. That's a real shame. Unfortunately, I can't think of a work around for that. I'll reply back again if I can come up with something.
Mike
Trying to do same, any way this can be accomplished?
what is the apex datatype the value attribute it is expecting?
I wrapped in a custom obj and tried to pass as Schema.SobjectField with no luck.
Ex.
ff.field = ((Schema.Sobjectfield)myLead.get(myFieldName));
...
<apex:inputField value="{!f.field}"/>