You need to sign in to do that
Don't have an account?

apex:selectList value is always returing null to controller
Im trying get the selected recordtype into the controller to build additional rendering logic in showTranLog() method based on input selection but its always returning null. when i insert the record in saveproceed() method its getting set fine.
<apex:page standardController="Contact" extensions="TaskExtensionCtrl"> <apex:form > <apex:pageBlock title="New Log" mode="edit" id='pb'> <apex:pageBlockSection id="selectedRecordType" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Choose Record Type" for="rt" /> <apex:panelGrid columns="2"> <apex:selectList value="{!selectedrecType}" multiselect="false" size="1" required="true"> <apex:selectOptions value="{!rectypes}"/> <apex:actionSupport event="onchange" action="{!showTranLog}" reRender="pb" status="status" immediate="true"/> </apex:selectList> </apex:panelGrid> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:pageBlockButtons location="bottom"> <apex:commandButton value="Save" action="{!saveAndProceed}" /> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>
Controller: public with sharing class TaskExtensionCtrl { public String partId; public Task task {get;set;} public boolean isShowTranLog {get;set;}{isShowTranLog=false;} public string selectedrecType{get;set;} public TaskExtensionCtrl(ApexPages.StandardController controller){ partId=ApexPages.currentpage().getParameters().get('id'); createTaskRecord(); } public void createTaskRecord() { system.debug(LoggingLevel.error,'in creat task'+selectedrecType); task = new Task(); } public PageReference showTranLog(){ this.isShowTranLog = true; system.debug(LoggingLevel.error,'task record type in showTranLog#'+ task.RecordTypeID+Task); return null; } public List<SelectOption> getrectypes() { List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('','--Select Record Type --')); for(RecordType rt:[select id,name from RecordType where sobjecttype='task']){ options.add(new SelectOption(rt.id,rt.name)); } return options; } public String getselectedrecType() { return selectedrecType; } public void setselectedrecType(String selectedrecType) { this.selectedrecType= selectedrecType; }
I am agree with Clint, Please change your controller class as below: Let me know if you still have any issue.
Thanks,
Abhishek