Skip to Content, PHP, MySQL, Javascript, Ajax, Htacces

Dynamic Visualforce Components Example

Be First!
by September 11, 2012 Uncategorized

Dynamic Visualforce Components Example:

Example of generate a dynamic input form for Account object

VisualForce Page:

<apex:page standardController="Account" extensions="DynamicAccountForm">
<!-- Create section header dynamically -->
<apex:dynamicComponent componentValue="{!SectionHeader}"/>
<apex:form >
<!-- Create dynamic input form for account object -->
<apex:dynamicComponent componentValue="{!ActionForm}"/>

Apex Class:

public with sharing class DynamicAccountForm
    public DynamicAccountForm(Apexpages.standardController ctlr)
    //Create a page block dynamically
    public Component.Apex.PageBlock getActionForm()
        Component.Apex.PageBlock pb = new Component.Apex.PageBlock();

        //creating an input field dynamically
        Component.Apex.InputField name = new Component.Apex.InputField();
        name.expressions.value = '{!Account.Name}'; = 'name';
        Component.Apex.OutputLabel label = new Component.Apex.OutputLabel();
        label.value = 'First Name';
        label.for = 'name';
        //Use the above block to create other input fields      
        Component.Apex.CommandButton save = new Component.Apex.CommandButton();
        save.value = 'Save';
        save.expressions.action = '{!Save}';
        return pb;

    //create section header dynamically
    public Component.Apex.SectionHeader getSectionHeader()
        Component.Apex.SectionHeader sh = new Component.Apex.SectionHeader();
        sh.title = 'Create Account';
        return sh;



Leave a Reply