+ Start a Discussion
AFawcett (CODA)AFawcett (CODA) 

Dynamically Adding Fields???

Because we don't always want to use <apex:detail> and yet still want our pages to respond to end user customisations of our objects. I’ve been looking at the <apex:repeat> tag to see what I can achieve as regards dynamically adding controls to a page. I’ve had partial success *, though I am binding to fields on Apex Classes again and not SObject fields ** so no <apex:inputField> benefits… L


* Can we nest <apex:repeat>’s as the drop down doesn’t appear to pick up the list items?  L


** Would be could to have indirect bindings e.g. <apex:inputField … value=”{!{!field.binding}}”> if you see what I mean?

<apex:page controller="dynamiccontroller">


<apex:repeat value="{!fields}" var="field" rows="50">


<td><apex:outputLabel value="{!field.label}"/></td>


<apex:inputText rendered="{!field.showText}" value="{!field.text}"/>

<apex:inputCheckbox rendered="{!field.showCheckbox}" value="{!field.boolean}"/>

<apex:selectOneListbox rendered="{!field.showValues}" value="{!field.text}" size="1">

<apex:repeat value="{!field.values}" var="fieldvalue" rows="50">

<apex:selectItem itemValue="{!fieldvalue.value}" itemLabel="{!fieldvalue.label}"/>









public class DynamicController


        DynamicFieldInfo[] fields;


        public DynamicFieldInfo[] getFields()




                        fields = new DynamicFieldInfo[3];


                        // Edit

                        fields[0] = new DynamicFieldInfo();

                        fields[0].setLabel('Field A');




                        // Checkbox

                        fields[1] = new DynamicFieldInfo();

                        fields[1].setLabel('Field B');




                        // Dropdown

                        fields[2] = new DynamicFieldInfo();

                        fields[2].setLabel('Field C');


                        List<DynamicFieldInfoValue> values = new List<DynamicFieldInfoValue>();

                        DynamicFieldInfoValue red = new DynamicFieldInfoValue();




                        DynamicFieldInfoValue yellow = new DynamicFieldInfoValue();






                return fields;



For truly dynamic component creation what you need is a feature (component binding) that we are currently developing as part of the custom components feature. Component binding is currently targeted to be released for dev preview as part of Spring '08.
Dogen ZenjiDogen Zenji
I can't seem to find documentation or examples of how to do server side component binding.  Would you please provide this assuming this is out in Summer 08 release?

Never mind.  I found the post here where you said it's not in summer 08.  What's the road map for releasing this feature?

Message Edited by Dogen Zenji on 06-27-2008 01:33 PM
Component binding support was #3 on our prioritized major feature list for the next release and I know now that we're only going to be able to deliver the top 2 features. I am pushing very hard to keep this at the top of the list for the release after that. Sorry - not getting this out to our customers has been very hard for my entire team but we need to get packaging support for VF components/pages released first.
Dogen ZenjiDogen Zenji
Makes perfect sense, packaging is definitely more important.  Thanks for the info!  Plus, I actually found another way to do what I wanted since all I wanted to change dynamically was the label for a button.  I just called a controller extension property from the command button value attribute and my getter does the logic to determine the correct output string as below. :smileyhappy:  Keep up the great work!

public String nextOrSave
  if(selectedProductMap.size() > 0)
   return 'Next';
   return 'Save';

<apex:commandButton value="{!nextOrSave}" action="{!next}"/>


Hehe - I would have given a very different (and shorter) answer if yoiu had asked "How do I dynamically change the label for a button?"...