Dynamic creation of pageBlockTable, sectionHeader, inputText(Visualforce components)

Sample code:

Visualforce page:

<apex:page standardController="Account" extensions="sample">
    <!-- Dynamic creation of Section Header -->
    <apex:dynamicComponent componentValue="{!secHead}"/>
    <apex:form >
        <!-- Dynamic creation of pageBlock -->
        <apex:dynamicComponent componentValue="{!formSample}"/>

Apex controller:

public class sample
    public sample(ApexPages.StandardController controller)

    //Dynamic creation of Section Header
    public Component.Apex.SectionHeader getsecHead()
        Component.Apex.SectionHeader sh = new Component.Apex.SectionHeader();
        sh.title = 'Create Account';
        return sh;
    //Dynamic creation of pageBlock
    public Component.Apex.PageBlock getformSample()
        Component.Apex.PageBlock pageBlock = new Component.Apex.PageBlock();
        //Dynamic creation of inputField
        Component.Apex.InputField name = new Component.Apex.InputField();
        name.expressions.value = '{!Account.Name}';
        name.id = 'name';
        Component.Apex.OutputLabel label = new Component.Apex.OutputLabel();
        label.value = 'Name';
        label.for = 'name';
        //Dynamic creation of CommandButton
        Component.Apex.CommandButton save = new Component.Apex.CommandButton();
        save.value = 'Save';
        save.expressions.action = '{!Save}';

        return pageBlock;


1 comment:

Sharing is Caring!!! Share this with your friends!!!

submit to reddit