title: How to get the selected value of a dynamically created selectlist component
body: <p>I am not sure whether this is even possible, but I am trying to get the values of dynamically created selectlists in a VisualForce Apex controller class.</p>
  
  <p>I am dynamically creating a selectlist for each field in a particular object (e.g. Contact) using the code below, but now I do not know how to get the selected value back. I have tried setting the value of each in the constructor and on a separate line (not in code sample below), but this does not seem to work.</p>
  
  <p>VisualForce page:</p>
  
  <pre><code>&lt;apex:dynamicComponent componentValue="{!contactPageBlockSection}" /&gt;
  </code></pre>
  
  <p>Apex controller:</p>
  
  <pre><code>public Component.Apex.PageBlockSection GetContactPageBlockSection(string objectName)   
  {
      Map&lt;string, Schema.SObjectField&gt; FieldMap;
      FieldMap = Schema.SObjectType.Contact.fields.getMap();
      Set&lt;string&gt; FieldSet = FieldMap.keySet();
      List&lt;string&gt; FieldList = new List&lt;string&gt;();
      FieldList.addAll(FieldSet);
      FieldList.sort();
      Component.Apex.PageBlockSection pbs = new Component.Apex.PageBlockSection(columns = 2);
  
      for (string fieldName : FieldList)
      {
          Component.Apex.PageBlockSectionItem pbsi = new Component.Apex.PageBlockSectionItem();
          Schema.DescribeFieldResult field = (FieldMap.get(fieldName)).getDescribe();
  
          if (field.isUpdateable() &amp;&amp; field.IsAccessible())
          {
              Schema.DisplayType dt = field.getType();
              Component.Apex.OutputLabel lblText = new Component.Apex.OutputLabel(escape = false);
              lblText.value = field.getLabel();
              pbsi.childComponents.add(lblText);
  
              Component.Apex.SelectList selList = new Component.Apex.SelectList(id = field.getName(), multiselect = false, size = 1, style = 'width:200px;');
  
              if (dt == Schema.DisplayType.Integer || dt == Schema.DisplayType.Double || dt == Schema.DisplayType.Currency || dt == Schema.DisplayType.Percent)
              {
                  AddSelectOption(selList, 'Keep highest value');
                  AddSelectOption(selList, 'Keep lowest value');
                  AddSelectOption(selList, 'Keep master value');
                  pbsi.childComponents.add(selList);
                  pbs.childComponents.add(pbsi);
              }
          }
      }
  
      return pbs;
  }
  
  private void AddSelectOption(Component.Apex.SelectList selList, string option)
  {
       Component.Apex.SelectOption selOption = new Component.Apex.SelectOption();
       selOption.itemLabel = option;
       selOption.itemValue = option;
       selList.childComponents.add(selOption);
  }
  </code></pre>
  
  <p>Many thanks in advance</p>