You need to sign in to do that
Don't have an account?
Vader
Picklist Rendering Issues
I have a picklist that I am trying to generate from a class. The idea is that when a user picks an item from the list that they will be redirected to the corresponding page. When I use the code snippet below in a test page where the class is set as the "Controller=class" it works great. However, when I add the class to another page as "extensions=class", the drop down list will not render any values.
Any ideas on how to get this to render properly.
Visualforce:
<apex:page standardController="Task" extensions="taskManagementRedirectPicklist" tabStyle="Task"> <apex:form > <apex:pageBlock title="Selection Criteria"> <apex:pageBlockSection showHeader="false" title="Options" columns="3"> <apex:pageBlockSectionItem > <apex:selectList value="{!picklistvalue}" size="1" > <Apex:selectOptions value="{!item}"/> <apex:actionSupport event="onchange" action="{!redirect}" /> </apex:selectList> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Apex Class:
public with sharing class taskManagementRedirectPicklist { private ApexPages.StandardController controller; public taskManagementRedirectPicklist(ApexPages.StandardController stdController) { controller = stdController; } public list<selectoption>item{get;set;} public string picklistvalue{get;set;} public taskManagementRedirectPicklist() { item=new list<selectoption>(); item.add(new selectoption('myTasks','Tasks Assigned to Me')); item.add(new selectoption('myDelegatedTasks','Tasks I Assigned to Others')); } public pagereference redirect() { PageReference pageRef= new PageReference('/apex/'+picklistvalue); pageRef.setredirect(true); return pageRef; } }
1. Change the VF page constructor to this Apex class by using controller="taskManagementRedirectPicklist" and not as extension.
2. Call the default controller in the constructor public taskManagementRedirectPicklist(ApexPages.StandardController stdController) by adding the line "this();" This should call the default constructor code and set the picklist
3. Add the code for picklist initialization to the parametrized constructor as well (this is a bad way of doing it due to introducing redundant code)
All Answers
1. Change the VF page constructor to this Apex class by using controller="taskManagementRedirectPicklist" and not as extension.
2. Call the default controller in the constructor public taskManagementRedirectPicklist(ApexPages.StandardController stdController) by adding the line "this();" This should call the default constructor code and set the picklist
3. Add the code for picklist initialization to the parametrized constructor as well (this is a bad way of doing it due to introducing redundant code)
I really appreciate the feedback!
Needed to go with option 2 above since I am using components from the Task object in other sections of the VF page.
There are so many holes in what I know regarding Apex and VF pages but as you stated above, the "this();" code line added to the constructor got it working. Just wish I understood fully why! :-) I never would have gotten that on my own. Thanks!
Corrected code below: