Firstly, I would use a CASE
instead of IF
in this case since you are always checking the same field value wrap.strdealerbaseparameter
.
I think that function below is more readable than what you have written.
{!CASE(wrap.strdealerbaseparameter,
'Retail', objPWDUT.AI_R0_Retail__c,
'Delivery', objPWDUT.AI_R0_Delivery__c,
'Booking', objPWDUT.AI_R0_Booking__c,
'TestDrive', objPWDUT.AI_R0_Test_Drive__c,
'Lead', objPWDUT.AI_R0_Lead__c,
'QualifiedLead', objPWDUT.AI_R0_Qualified_Lead__c,
objPWDUT.AI_R0_Retail__c)}"
However, you can't use "static" binding in any other type of formula, so you have to be willing to use "dynamic" binding instead. Here's what that looks like:
<apex:inputField value="{!objPWDUT[CASE(wrap.strdealerbaseparameter,
'Retail','AI_R0_Retail__c',
'Delivery','AI_R0_Delivery__c',
'Booking', 'AI_R0_Booking__c',
'TestDrive', 'AI_R0_Test_Drive__c',
'Lead', 'AI_R0_Lead__c',
'QualifiedLead', 'AI_R0_Qualified_Lead__c',
'AI_R0_Retail__c')]}" />
The []
syntax in Visualforce allows you to specify a string (even as the result of a formula evaluation) to determine which field to render/bind to, thus being "dynamic." You'll get runtime exceptions if the field name is misspelled or not queried in the original query.
See below for prior version:
However, this won't solve your problem as you can't have this sort of "dynamic binding" in the value
attribute of apex:inputField
(AFAIK).
What you can do is render different apex:inputField
based on the the value of the wrap.strdealerbaseparameter
property. Something like below:
<apex:inputField render="{!wrap.strdealerbaseparameter=='Retail'}" value="{!objPWDUT.AI_R0_Retail__c}"/>
<apex:inputField render="{!wrap.strdealerbaseparameter=='Delivery'}" value="{!objPWDUT.AI_R0_Delivery__c}"/>
<apex:inputField render="{!wrap.strdealerbaseparameter=='Booking'}" value="{!objPWDUT.AI_R0_Booking__c}"/>
<!-- etc. -->
That's the best I can come up with at the moment. Maybe someone else will have a better solution.