function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tim Johnson-Reynolds 8Tim Johnson-Reynolds 8 

visualforce dynamic components not storing value in sobject variable

Hi
I am using a dynamic component on a visualforce page to allow for a configurable layout defined by custom metadata types. This is my get class in my controller 
 
public Component.Apex.PageBlockSection getDynamicPageSection(){
        
        Map<String, Schema.SObjectField> caseFields = Schema.SObjectType.Case.fields.getMap();
        
        Component.Apex.PageBlockSection pageBlock = new Component.Apex.PageBlockSection();
        pageBlock.columns=1;
        
        list<Sales_Tool_Page_Sections__mdt> sectionsfields = new list<Sales_Tool_Page_Sections__mdt>([Select id, Label, order__c, (Select id, Field_Api_Name__c, order__c, required__c from Sales_Tool_Section_Fields__r order by Order__c asc ) From Sales_Tool_Page_Sections__mdt where Sales_Tool_Request_Type__c =:strType order by Order__c asc]);
        
        for(Sales_Tool_Page_Sections__mdt ps:sectionsfields){
            system.debug('Page Section Order: ' + ps.order__c);
            Component.Apex.PageBlockSection pbs = new Component.Apex.PageBlockSection();
			pbs.title = ps.label;   
            
            
            for (Sales_Tool_Section_Field__mdt f:ps.Sales_Tool_Section_Fields__r){
            	system.debug('Order: ' + f.order__c);
                if(caseFields.containskey(f.Field_Api_Name__c)){
                    Component.Apex.InputField newfield = new Component.Apex.InputField();

                    newfield.expressions.value = '{!stCase.' + f.Field_Api_Name__c + '}';
              
                    
                    system.debug(newfield.expressions.value);
                    newfield.id = f.Field_Api_Name__c;
                    newfield.required = f.required__c;
                    
                    Component.Apex.ActionRegion ar = new Component.Apex.ActionRegion();
                    Component.Apex.ActionSupport asup = new Component.Apex.ActionSupport();
                    asup.event='onchange';
                    asup.expressions.action='{!fieldCheck}';
                    ar.childcomponents.add(asup);
					newfield.childcomponents.add(ar);
                    
                    pbs.childComponents.add(newfield);
                }
            }
            
            
            pageBlock.childComponents.add(pbs);
        }
       
       
        Return pageBlock;
        
    }

And this is the component on the page:
 
<apex:dynamicComponent id="dynamicSection" componentValue="{!dynamicPageSection}" rendered="{!strTool!=null&&strType!=null&&casenum==null}"/>

The component is rendered following selection of other fields defined on the page. It builds the dynamic page sections correctly and they function normally apart from the fact that the values entered into the dynamic input fields don't appear to be saving the values to the sobject and field defined in the value expression. On inserting the record I just have blank values. 

I have tried all sorts of things to determine the cause of this, and this is my first attempt at dynamic components. Any help to fix this issue would be greatly appreciated. 

Thanks
Best Answer chosen by Tim Johnson-Reynolds 8
Tim Johnson-Reynolds 8Tim Johnson-Reynolds 8
I have managed to solve this myself. The changes I made were a red herring. I had also added a rerender statement on my save action and this was clearing the form before I inserted the record.