function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chamil MadusankaChamil 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;
    }
}

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Chamil MadusankaChamil Madusanka

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;

 

String para1=Apexpages.currentPage().getParameters().get('para');

 Here is the example code.

 

/*Visual page*/.

 

<apex:page standardController="Applicant__c" extensions="view">

<script type="text/javascript">
function getSelectedID(id) {
viewFunction(document.getElementById(id).value);
}
</script>


<apex:form >

<apex:actionFunction name="viewFunction" id="vfunc" action="{!getApplicantByStatus}" rerender="view">
<apex:param name="para" value=""/>

</apex:actionFunction>

<apex:pageBlock >
<apex:outputLabel value="Status :" for="status"/>
<apex:inputField id="status" value="{!Applicant__c.Status__c}" onchange="getSelectedID('{!$Component.status}');">
</apex:inputField>
</apex:pageBlock>

<apex:pageBlock >
<apex:panelgroup id="view">
<apex:pageBlockTable id="viewApplicant" value="{!applicantByStatusList}" var="app">

<apex:column headerValue="Applicant ID" value="{!app.Name}">
</apex:column>

<apex:column headerValue="Applicant Name" value="{!app.Name__c}">
</apex:column>
<apex:column headerValue="Interview Date" value="{!app.Interview_Date_Time__c}">
</apex:column>
</apex:pageBlockTable>
</apex:panelgroup>
</apex:pageBlock>

</apex:form>
</apex:page>

 

/*Controller*/

 

 

public class view {

public view(ApexPages.StandardController controller) {

}

public Applicant__c applicant;
public List<Applicant__c> applicantByStatusList {get;set;}
private ApexPages.StandardSetController controller;

public List<String> applicantNameByStatus{
get;
set;

}





public view(ApexPages.StandardSetController controller) {
this.applicant=(Applicant__c)controller.getRecord();

}


public PageReference getApplicantByStatus(){

String para1=Apexpages.currentPage().getParameters().get('para');

applicantByStatusList =new List<Applicant__c>();
applicantNameByStatus=new List<String>();
applicantByStatusList =[SELECT Name,Name__c,Status__c,Interview_Date_Time__c FROM Applicant__c WHERE Status__c =:para1];


for(Applicant__c a:applicantByStatusList){
String name=(String)a.Name;
applicantNameByStatus.add(name);

}


return null;
}
}

 

This could meet my requirement.

:smileyvery-happy:

 

 

All Answers

Shailesh DeshpandeShailesh Deshpande

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.

 

 

 

Chamil MadusankaChamil Madusanka

I did the changes as u said. But the result is same as previous.

<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:actionSupport>
</apex:inputField>
</apex:pageBlock>

 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?

 

 

bob_buzzardbob_buzzard

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.

Shailesh DeshpandeShailesh Deshpande

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.

Chamil MadusankaChamil Madusanka

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?

bob_buzzardbob_buzzard

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:

 

 

 applicantByStatusList =[SELECT Name,Name__c,Status__c,Interview_Date_Time__c FROM Applicant__c WHERE Status__c =:applicant.Status__c];

 

as the applicant will be updated with the user's selection by the time your action method is called.

 

Pratibh PrakashPratibh Prakash

Hello,

 

Please change the visual force code as:

 

 

<apex:actionSupport event="onchange" action="{!getApplicantByStatus}" reRender="view">
  <apex:param name="para" value="{!Applicant__c.Status__c}" assignTo="{!para}"/>
</apex:actionSupport>

 

 

Chamil MadusankaChamil Madusanka

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];

bob_buzzardbob_buzzard

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?

 

Chamil MadusankaChamil Madusanka

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;

 

String para1=Apexpages.currentPage().getParameters().get('para');

 Here is the example code.

 

/*Visual page*/.

 

<apex:page standardController="Applicant__c" extensions="view">

<script type="text/javascript">
function getSelectedID(id) {
viewFunction(document.getElementById(id).value);
}
</script>


<apex:form >

<apex:actionFunction name="viewFunction" id="vfunc" action="{!getApplicantByStatus}" rerender="view">
<apex:param name="para" value=""/>

</apex:actionFunction>

<apex:pageBlock >
<apex:outputLabel value="Status :" for="status"/>
<apex:inputField id="status" value="{!Applicant__c.Status__c}" onchange="getSelectedID('{!$Component.status}');">
</apex:inputField>
</apex:pageBlock>

<apex:pageBlock >
<apex:panelgroup id="view">
<apex:pageBlockTable id="viewApplicant" value="{!applicantByStatusList}" var="app">

<apex:column headerValue="Applicant ID" value="{!app.Name}">
</apex:column>

<apex:column headerValue="Applicant Name" value="{!app.Name__c}">
</apex:column>
<apex:column headerValue="Interview Date" value="{!app.Interview_Date_Time__c}">
</apex:column>
</apex:pageBlockTable>
</apex:panelgroup>
</apex:pageBlock>

</apex:form>
</apex:page>

 

/*Controller*/

 

 

public class view {

public view(ApexPages.StandardController controller) {

}

public Applicant__c applicant;
public List<Applicant__c> applicantByStatusList {get;set;}
private ApexPages.StandardSetController controller;

public List<String> applicantNameByStatus{
get;
set;

}





public view(ApexPages.StandardSetController controller) {
this.applicant=(Applicant__c)controller.getRecord();

}


public PageReference getApplicantByStatus(){

String para1=Apexpages.currentPage().getParameters().get('para');

applicantByStatusList =new List<Applicant__c>();
applicantNameByStatus=new List<String>();
applicantByStatusList =[SELECT Name,Name__c,Status__c,Interview_Date_Time__c FROM Applicant__c WHERE Status__c =:para1];


for(Applicant__c a:applicantByStatusList){
String name=(String)a.Name;
applicantNameByStatus.add(name);

}


return null;
}
}

 

This could meet my requirement.

:smileyvery-happy:

 

 

This was selected as the best answer
bob_buzzardbob_buzzard
Glad to hear you got there in the end.