You need to sign in to do that
Don't have an account?
Chamil Madusanka
<apex:param> in selectList
I have used <apex:param> in a selectList. But it doesn't pass the parameter to the controller. Is there any solution for this case?
<apex:page standardController="Applicant__c" recordSetVar="applicant" extensions="view">
<apex:form >
<apex:pageBlock > <apex:outputLabel value="Status :" for="status"/> <apex:inputField id="status" value="{!Applicant__c.Status__c}"> <apex:actionSupport event="onchange" action="{!getApplicantByStatus}" reRender="view"/> <apex:param name="para" value="{!Applicant__c.Status__c}" assignTo="{!para}"/> </apex:inputField> </apex:pageBlock>
</apex:form>
</apex:page>
public class view { public Applicant__c applicant; public List<Applicant__c> applicantByStatusList {get;set;} private ApexPages.StandardSetController controller; public List<String> applicantNameByStatus{get;set;} public String para{ get; set{ para=value; } } public view(ApexPages.StandardSetController controller) { this.applicant=(Applicant__c)controller.getRecord(); //this.controller = controller; } /* public List<String> getApplicantByStatus(){ applicantByStatusList =new List<Applicant__c>(); applicantByStatusList =[SELECT Name,Name__c,Status__c,Interview_Date_Time__c FROM Applicant__c WHERE Status__c =:para]; if(applicantByStatusList ==null){ System.Debug('APPLICANT STATUS IS NULL'); } for(Applicant__c app:applicantByStatusList ){ String name=app.Name__c; System.Debug('CHECK :: '+app.Name__c); applicantNameByStatus.add('app.Name__c'); } //applicantNameByStatus.add('Chamil'); //applicantNameByStatus.add('madusanka'); // applicantNameByStatus.add('applicant1'); return applicantNameByStatus; } */ public PageReference getApplicantByStatus(){ applicantByStatusList =new List<Applicant__c>(); System.Debug('PARAMETER :: '+para); applicantByStatusList =[SELECT Name,Name__c,Status__c,Interview_Date_Time__c FROM Applicant__c WHERE Status__c =:para]; if(applicantByStatusList !=null){ for(Applicant__c app:applicantByStatusList ){ String name=app.Name__c; System.Debug('CHECK :: '+app.Name__c); applicantNameByStatus.add('app.Name__c'); } }else{ System.Debug('APPLICANT STATUS IS NULL'); } //applicantNameByStatus.add('Chamil'); //applicantNameByStatus.add('madusanka'); // applicantNameByStatus.add('applicant1'); return null; } }
I have solved that problem in other way.
First call the javaScript when change the value of selectList. Then the javaScript function will get the current value of selectList and contact with the actionFunction "viewFunction" . "viewFunction" call the action method "getApplicantByStatus" with the parameter. we can get the parameter in controller as follows;
Here is the example code.
/*Visual page*/.
/*Controller*/
This could meet my requirement.
:smileyvery-happy:
All Answers
1) put ur param tag within the action support tag.
2) try using public String para {get;set;}. instead of the way u have defined.
I did the changes as u said. But the result is same as previous.
But if we hardcode the value of param (highlighled one),it gives the result according to the hardcoded parameter. If we change the values as in code. it never works.
What will be the issue?
I'd imagine you are expecting the user's selection to be passed back to the controller by the parameter. This won't work, as the apex:param component is generated when the page is first rendered, which means it will contain the value of Applicant__c.Status__c prior to the user making any selection.
I'm a bit confused about why you want to pass this parameter anyway. The Applicant__c.Status__c is already used to back an input field, so when the getApplicantByStatus method is executed, Applicant__c.Status__c will be updated with the user's selection.
can u just check if u r getting the data when u change the picklist value by putting a debug in ur getApplicant function.
system.debug(applicant);
Since u r using an input field, i dont think u need to pass a param here.
I want to get the applicants who in particular status. That's why I try to pass the parameter to the controller. Take a look at very first post to clarify.How can I do that?
That won't work, as the parameter that is passed back to the controller won't be the user's selection, it will be the value of the field when the page was rendered.
Given that your inputfield is backed by Applicant__c.Status__c, you should be able to change your soql to:
as the applicant will be updated with the user's selection by the time your action method is called.
Hello,
Please change the visual force code as:
I did the changes. But I'm still getting following exception when change the value of selectList.
System.NullPointerException: Attempt to de-reference a null object
Class.view.getApplicantByStatus: line 55, column 123 External entry point
@ line 55
applicantByStatusList =[SELECT Name,Name__c,Status__c,Interview_Date_Time__c FROM Applicant__c WHERE Status__c =:applicant.Status__c];
This implies that applicant is null, which shouldn't be the case given that you have initialised it in the view method. Have you checked that this method is being invoked when the controller is created?
I have solved that problem in other way.
First call the javaScript when change the value of selectList. Then the javaScript function will get the current value of selectList and contact with the actionFunction "viewFunction" . "viewFunction" call the action method "getApplicantByStatus" with the parameter. we can get the parameter in controller as follows;
Here is the example code.
/*Visual page*/.
/*Controller*/
This could meet my requirement.
:smileyvery-happy: