0

I have a custom object Response__c as shown below.

enter image description here

xx,yy,zz are different field values for the three records.

Please note that not all fields are populated for all the three records.

A single apex:inputfield is to be shown in the VF Page whose "value" property will be determined at runtime

I followed an earlier post's advice

VF component dynamic inputField

and refactored my code as below

Component markup

<apex:component controller="DynamicApexController" >
    <apex:attribute name="inputObject" type="sObject" description="Object Name"/>
    <apex:attribute name="inputFieldName" type="String" description="Field Name"/>
    <apex:inputField value="{!r[inputFieldName]}"/>
</apex:component>

Component controller

public with sharing class DynamicApexController {

public Response__c r {get;set;}
public Response__c getr()
{

Response__c newr = new Response__c();
return newr;

}



}

Visualforce Page

<!-- Page: -->

<apex:page >
<apex:form >

    <c:myComponent1 myValue="My composents value" borderColor="green" /> 
    <c:dynamicinput inputFieldName="Field1__c"  id="first" rendered="true" />
</apex:form>
</apex:page>

But I am getting the following error when navigating to the VF Page. Attached is the error screenshot below.

Can someone let me know what is wrong ?

Error Screenshot

enter image description here

0

Please have a look at this - VF component dynamic inputField.

I think you should replace r with attribute inputobject and pass the inputobject parameter from VF to even make sobject dynamic.

Thanks, Abhishek

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.