You need to sign in to do that
Don't have an account?
selected picklist value is not getting into controller
hi,
I am learning Apex and VF. I need to display the records based on the selected department. When I trying to get the selectedpick list value in my controller it is not getting returned.
Please suggest me some solution.
public class deptpicklistctrl{
public void search() {
system.debug('****in getemplist****');
empobj = [select name,empname__c,empid__c,deptid__c from emp__c where deptid__c=:selectedval];
//system.debug(empobj.get(0).name);
//Pagereference p= apexpages.currentpage();
//return p;
}
public List<dept__c> deptobj{get;set;}
public List<emp__c> empobj{get;set;}
public String selectedval{get{return selectedval;}set{this.selectedval=selectedval;}}
public deptpicklistctrl()
{
//search();
}
public List<SelectOption> getDeptnos(){
deptobj = [select name from dept__c];
List<SelectOption> lis = new List<SelectOption>();
for(dept__c d:deptobj){
lis.add(new SelectOption(d.name,d.name));
}
return lis;
}
}
// VF page
<apex:page controller="deptpicklistctrl" showHeader="false">
<apex:form >
<apex:pageBlock mode="edit">
<apex:pageBlockSection title="Select from Pick List">
<apex:outputText value="Department : "/>
<apex:selectList value="{!selectedval}" size="1">
<apex:selectOptions value="{!deptnos}"></apex:selectOptions>
</apex:selectList>
<apex:commandButton value="Search" action="{!search}" reRender="block" />
</apex:pageBlockSection>
</apex:pageblock>
<apex:pageBlock mode="edit" id="block">
<apex:pageblockSection title="Employee List in the department">
<apex:pageBlockTable value="{!empobj}" var="bj">
<apex:column value="{!bj.name}"/>
<apex:column value="{!bj.EmpName__c}"/>
<apex:column value="{!bj.EmpID__c}"/>
<apex:column value="{!bj.DeptID__c}"/>
</apex:pageBlockTable>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
In your setter:
You are setting selectedval to itself. To use the value from the page, you set it to "value, e.g.
However, as you aren't doing anything special you can use an automatic property rather than writing the getter and setter: