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
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">

<table>

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

<tr>

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

<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}"/>

</apex:repeat>

</apex:selectOneListbox>

</td>

</tr>

</apex:repeat>

</table>

</apex:page>

 

public class DynamicController

{

        DynamicFieldInfo[] fields;

 

        public DynamicFieldInfo[] getFields()

        {

                if(fields==null)

                {

                        fields = new DynamicFieldInfo[3];

 

                        // Edit

                        fields[0] = new DynamicFieldInfo();

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

                        fields[0].setShowText(true);

                        fields[0].setText('Text');

 

                        // Checkbox

                        fields[1] = new DynamicFieldInfo();

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

                        fields[1].setShowCheckbox(true);

                        fields[1].setBoolean(true);

 

                        // Dropdown

                        fields[2] = new DynamicFieldInfo();

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

                        fields[2].setShowValues(true);

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

                        DynamicFieldInfoValue red = new DynamicFieldInfoValue();

                        red.setValue('red');

                        red.setLabel('Red');

                        values.add(red);

                        DynamicFieldInfoValue yellow = new DynamicFieldInfoValue();

                        yellow.setValue('yellow');

                        yellow.setLabel('Yellow');

                        values.add(yellow);

                        fields[2].setValues(values);

                }                

                return fields;

        }

}

dchasmandchasman
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
dchasmandchasman
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!

Code:
public String nextOrSave
{
 get
 {
  if(selectedProductMap.size() > 0)
   return 'Next';
  else
   return 'Save';
 }
}    

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

 

dchasmandchasman
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?"...