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 ChadbournSteve Chadbourn 

Field dependencies don't work with custom controllers?

I have a checkbox field and a picklist field. I set up a field dependency so that if the checkbox is checked, all the picklist values are available but if the checkbox is unchecked none of them are. It all works fine in the preview.
 
The dependency does not work however on my visualforce page.
 
The page it should work on is one of a number of wizard pages controlled by a custom controller. Should dependencies work with a custom controller?
 
When I refresh my Eclipse object from the server I cannot see any dependency information. Where is this defined?
TehNrdTehNrd
I would be interested to know this as well. In my case I have two picklists, one controller and one dependent. The controller is Theater and this drives a Distributor picklist.  The distributor picklist shows all values regardless of Theater selection.

This behavior is not limited to custom controllers. Dependent picklist do not work with the standard controller either.

Thanks,
Jason



Message Edited by TehNrd on 03-19-2008 05:01 PM
HalcyonandonHalcyonandon
I just recently got the dependent picklists working following the example at http://wiki.apexdevnet.com/index.php/Extended_Functionality_of_Visualforce_-_Part_2

I wrote an extension to a custom controller to get my desired results.  I posted all my code in a thread I recently created.  If you think it will help, let me know and I'll post my code in this thread too.
TehNrdTehNrd
I saw that as well but it would require building out a reference table to drive the pick lists.
HalcyonandonHalcyonandon
reference table?  I'm not quite sure what you mean, I followed the example, created one picklist populated from a custom object with a look up relationship to another object that populated the second... there were no tables involved and it worked out just fine.  I did have to write it using a standard controller and extended it with a custom controller...

Here is my controller extension...

public class helpFormController {

public helpFormController (ApexPages.StandardController stdController){

}
/* String value for the grouping */
String grouping;

/* String value for the category */
String category;

/* Getter for the grouping value */
public String getGrouping() { return this.grouping; }

/* Setter for the grouping value */
public void setGrouping(String s) { this.grouping = s; }

/* Getter for the category value */
public String getCategory() { return this.category; }

/* Setter for the category value */
public void setCategory(String s) { this.category = s; }

/* Getter which dynamically generates the groupings from the Grouping__c object. */
public List<SelectOption> getGroupings() {
List<SelectOption> optionList = new List<SelectOption>();
/* Add a null option to force the user to make a selection. */
optionList.add(new SelectOption('','- None -'));

/* Loop through the feature_category__c records creating a selectOption
for each result with the record ID as the value and the name as the label
displayed in the selectList */

for (Grouping__c fc: [select name from Grouping__c order by Name]){
optionList.add(new SelectOption(fc.id,fc.name));
}
return optionList;
}
/* Getter which generates the options for the Topic selectList based on the current
value of the selected category. If there is no value selected then only
the null option should be returned. */


public List<SelectOption> getCategories() {
List<SelectOption> optionList = new List<SelectOption>();
/* Add a null option to force the user to make a selection. */
optionList.add(new SelectOption('', '- None -'));

/* If a category has been selected then query for the related values */
if(grouping!= NULL) {

/* Loop over the related feature records for the given category
creating a selectOption with the value being the feature record ID
and the label is the name of the feature. */

for (Category__c f : [select name from Category__c f where f.Grouping__c = :grouping]){
optionList.add(new SelectOption(f.name,f.name));
}
}
return optionList;
}
}


And here is my visualforce page code...

<apex:page showheader="true" standardcontroller="Topic__c" extensions="helpFormController" id="UseCaseDisplay" label="TopicCategoryReport" >

<apex:form>


<apex:outputLabel value="Grouping:" for="grouping"/>
<apex:selectList value="{!grouping}" size="1" id="grouping">

<apex:selectOptions value="{!groupings}"/>
<apex:actionSupport event="onchange" rerender="categories"/>
</apex:selectList>
<a class="title" href="/apex/addgrouping" target="_blank">New</a>
<br /> <br />

<apex:outputLabel value="Category:" for="categories"/>
<apex:selectList value="{!Category}" size="1" id="categories" disabled="{!ISNULL(grouping)}">
<apex:selectOptions value="{!Categories}"/>
</apex:selectList>
<a class="title" href="/apex/addcategory" target="_blank">New</a>
<br /> <br />
<h2>New Topic: </h2>
<apex:inputField value="{!Topic__c.name}" id="topic"/><br /><br />
<h2>Directions: </h2><br />
<apex:inputtextarea id="directions" cols="100" rows="25" value="{!Topic__c.Directions__c}"/> <br /><br />
<apex:commandButton value="Save" action="{!Save}" onClick="beforeTextSave()"/>
</apex:form>
</apex:page>
TehNrdTehNrd
Your custom object is essentially your reference table. Based on the grouping selected you run a query to return all of the categories.

This wouldn't work for a standard dependent picklist as there is nothing to query on. We have a two picklists on Opportunity. Theater and Distributor. Theater controls Distributor.  To make this work I would need to create a reference table (custom object) with two fields, Theater and Distributor, ever time Theater was selected (onchange) run a query on the custom object to return the Distributor.

jayamjayam

please post ur code for dependent picklists in v.f page

 

 

 

Thanks in advance............

TehNrdTehNrd

This is now a supported feature, check documentation.

maxout2maxout2

Is it supported now?

A test is created with a custom controller and a VF page, but no dependenciies happen.

It seems like there is no link between the field dependencies and the custom controller/VF page.

Is there any extra setting needed to be done.

any one find the link for the document. Thanks