You need to sign in to do that
Don't have an account?
rohitash yadav
Pass picklist selected value from visualforce page to apex class
Hi
I have some records listing on visualforce page . I want to filter these records based on selected value of custom picklist. I am not able to get selected value of this picklist in apex class.
My visualforce page is:
Apex class is:
When I change the value of picklist it throws the following error
Attempt to de-reference a null object
Error is in expression '{!filterPackages}' in page addopportunitylineitem1: Class.LineItemPackagesExtensions.filterPackages: line 35, column 1
Please help to achieve this.
Thanks
Rohitash
I have some records listing on visualforce page . I want to filter these records based on selected value of custom picklist. I am not able to get selected value of this picklist in apex class.
My visualforce page is:
<apex:page standardController="Line_Item__c" extensions="LineItemPackagesExtensions" recordSetVar="lineitems" > <apex:pageBlock title="Search for Packages"> <apex:outputLabel >Packages Category</apex:outputLabel> <apex:inputField value="{!prdcat.Product_Category__c}" > <apex:actionSupport event="onchange" rerender="packagesList" action="{!filterPackages}"/> </apex:inputField> <apex:outputPanel id="packagesList"> <apex:pageBlockTable value="{!Packages}" var="a"> <apex:column value="{!a.Name}"/> <apex:column value="{!a.Product_Category__c}"/> <apex:column value="{!a.Cost__c}"/> <apex:column value="{!a.Stay__c}"/> <apex:column value="{!a.Activity__c}"/> <apex:column value="{!a.Description__c}"/> </apex:pageBlockTable> </apex:outputPanel> </apex:pageBlock> </apex:page>
Apex class is:
public class LineItemPackagesExtensions { public Package__c pkgs; public List<Package__c> Packages { get; set; } public Package__c prdcat{get;set;} public LineItemPackagesExtensions(ApexPages.StandardSetController controller) { Packages = [SELECT Name,Product_Category__c,Cost__c,Stay__c,Activity__c,Description__c FROM Package__c ]; } public List<Package__c> getPackages(){ Packages = [SELECT Name,Product_Category__c,Cost__c,Stay__c,Activity__c,Description__c FROM Package__c ]; return Packages; } public void filterPackages() { Packages = [SELECT Name,Product_Category__c,Cost__c,Stay__c,Activity__c,Description__c FROM Package__c where Product_Category__c=:prdcat.Product_Category__c ]; } }
When I change the value of picklist it throws the following error
Attempt to de-reference a null object
Error is in expression '{!filterPackages}' in page addopportunitylineitem1: Class.LineItemPackagesExtensions.filterPackages: line 35, column 1
Please help to achieve this.
Thanks
Rohitash
Initialize your package in controller before accessing it in UI. as it seems that you haven't initialized it.
Hope it will help you.
Mark it as best answer if it resolves your query.
Thanks
All Answers
Initialize your package in controller before accessing it in UI. as it seems that you haven't initialized it.
Hope it will help you.
Mark it as best answer if it resolves your query.
Thanks
Thanks, It is working now. I will let you know if I need more help to complete task further.
Thanks,
Rohitash singh yadav