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
steve_andersensteve_andersen 

Can't get SelectOptions to display

I am building a data entry form with 3 picklists--Account, Opportunity, and a custom child object of opportunity. The idea is you select an Account, and then get a picklist of all Opportunites, when you select an Opp, the child picklist shows up.

I built an interface like this in an scontrol and I'm now replacing it with VF.

I built a client object, which has an Account Id, Account Name, and a list of SelectOptions for available Opportunities:
public class client {
 public Id clientId;
 public String clientName {get{return clientName;} set{clientName = value;}}
 public List<SelectOption> projectOptions {get{return projectOptions;} 
set{projectOptions = value;}} public Map<Id,project> projects {get{return projects;} set{projects = value;}} public client() { projectOptions = new List<SelectOption>(); projects = new Map<Id,project>(); } }

On page load I build out a map of all my clients, each with it's projectOptions. When I debug the client object I get this:
001S0000003VuzSIAS=timesheetController.client: [
clientId=001S0000003VuzSIAS,
clientName=ONE/Northwest,
     projectOptions=(
          System.SelectOption[value="", label="- pick a project -", disabled="false"],     
          System.SelectOption[value="006S0000002JUkiIAG", label="ONE/Northwest 2008 Project", disabled="false"] ),
.
.
.

 But I can't get the project options to show in a picklist. The client picklist works, and when you change it, it rerenders the project section. But the project picklist is empty, and I can't get the project options that I know are there to show up.:

<tbody>
         
 <tr><th><apex:outputText value="AccountNew"/></th>
  <td>
   <apex:selectList value="{!newTaskLog.Account__c}" id="accountselect" 
multiselect="false" size="1"> <apex:selectOptions value="{!clientSelect}"/> <apex:actionSupport event="onchange"
action="{!setupFocusClient}" rerender="projectselect"/> </apex:selectList> </td></tr> <tr><th><apex:outputText value="ProjectNew"/></th> <td> <apex:outputPanel id="projectselect" > <apex:outputText value="{!focusClient.clientName}"/> <apex:selectList value="{!newTaskLog.Opportunity__c}"
multiselect="false" size="1"> <apex:selectOptions value="{!focusClient.projectOptions}"/> <apex:actionSupport event="onchange"
action="{!setupFocusProject}" rerender="taskSelect"/> </apex:selectList> </apex:outputPanel> </td></tr>

Any ideas about what I'm doing wrong?

Thanks,
Steve
 

DSchachDSchach
Steve-
There is an example of creating dynamic/dependent picklists in the Force.com Developer Guide, pages 366 to 379.  That should help you.  Plus, you may be able to combine that with code to display a lookup field as a picklist.
Hope that helps,
David
steve_andersensteve_andersen
Thanks Dave! Directly on point. My main problem seems that I was trying to bind my picklists directly to my fields. Thanks for the reference.

Steve
steve_andersensteve_andersen
I fixed the problem with me trying to bind directly to the Id fields. I now have the select lists binding to intermediary strings.

But my main problem still exists--My select options are in my data structure but not showing in my select list.

The projectOptions property of my focus client is a list with two selectOptions in it. I have a selectlist bound to it. But the two options don't show in the pick list. The data is there in the structure, but the page isn't getting it for some reason. I can't figure it out.

Am I missing something?
steve_andersensteve_andersen
Fixed this by adding a selectList to the controller and putting the class selectList in it. Seems like housekeeping I'd rather not do, but it works.

Steve