Dynamic Binding of input fields
Example 1: Dynamic Binding of input fields
In scenario we used apex:repeat to get all inputfields dynamically.
page:
<apex:page sidebar=”false” standardController=”Testing__c” extensions=”DynamicBindingFieldsOnVFPage”>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection columns=”1″>
<apex:repeat value=”{!fields}” var=”f”>
<apex:inputfield value=”{!Testing__c[f]}”/>
</apex:repeat>
</apex:pageBlockSection>
<apex:commandButton value=”Insert” action=”{!doSave}”/>
</apex:pageBlock>
</apex:form>
</apex:page>
class:
public with sharing class DynamicBindingFieldsOnVFPage {
public DynamicBindingFieldsOnVFPage(ApexPages.StandardController controller) {
}
public pagereference dosave()
{
return null;
}
public List<String> lstfields = new List<String>();
public List<String> getfields(){
lstfields.add(‘Name’);
lstfields.add(‘city__c’);
return lstfields;
}
Example2: Component
code for component
<apex:component >
<apex:form >
<apex:outputtext value=”Welcome To Hyderabad” style=”color:blue;font-size:30px;”>
</apex:outputtext>
</apex:form>
</apex:component>
calling VF component:
/apexcomponent/componentName
page:
<apex:page sidebar=”false” standardController=”Testing__c” extensions=”DynamicBindingFieldsOnVFPage”>
<c:co1 />
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection columns=”1″>
<apex:repeat value=”{!fields}” var=”f”>
<apex:inputfield value=”{!Testing__c[f]}”/>
</apex:repeat>
</apex:pageBlockSection>
<apex:commandButton value=”Insert” action=”{!doSave}”/>
</apex:pageBlock>
</apex:form>
<c:co1 />
</apex:page>
class:
public with sharing class DynamicBindingFieldsOnVFPage {
public DynamicBindingFieldsOnVFPage(ApexPages.StandardController controller) {
}
public pagereference dosave()
{
return null;
}
public List<String> lstfields = new List<String>();
public List<String> getfields(){
lstfields.add(‘Name’);
lstfields.add(‘city__c’);
return lstfields;
}
}
can anyone explain what exactly we are doing in first example here,what is the repeat tag doing, when i run this code in my org using Account object, each time i hit insert the number of input fields increase thats it.