+ Start a Discussion

not able to get values into the controller from the VF page

Hi all,


am new to visual force and am trying to get values from my visual force page for further processing but am getting null values in my controller .


Can any one let me know what is the problem??


Here is my code snippet.


VF page :




<apex:page controller="paginationController">
<apex:form >
    <apex:pageBlock mode="edit" title="Search">
    function scriptSearch(){
    <apex:actionFunction name="searchCall" action="{!searchFunctionality}">
    <apex:param name="firstname" value="" />
    <apex:param name="lastname" value="" />
    <apex:param name="country" value="" />
                <td>First Name : <input type="text" id="firstName"/></td>
                <td>Last Name: <input type="text" id="lastName"/></td>
                Country : <select id="country">
                <option value=""></option>
                <apex:repeat value="{!countries}" var="country">
                <option value="{!country}">{!country}</option>
                <td><apex:commandButton onclick="scriptSearch();" value="Search"/></td>
    <apex:pageBlock title="Debug - SOQL" id="debug">
      <apex:outputText value="{!queryString}" />           



Controler :




public class paginationController {


public string queryString{get;set;}


public List<SampleObject001__c> userDetails{get;set;}


public paginationController(){

 queryString='Select First_Name__c,Last_Name__c,Country__c From SampleObject001__c';



public List<String> countries {

    get {

      if (countries == null) {


        countries = new List<String>();

        Schema.DescribeFieldResult field = SampleObject001__c.Country__c.getDescribe();


        for (Schema.PicklistEntry f : field.getPicklistValues())




      return countries;          





 public PageReference searchFunctionality(){


  String firstName = Apexpages.currentPage().getParameters().get('firstname');

    String lastName = Apexpages.currentPage().getParameters().get('lastname');

    String country = Apexpages.currentPage().getParameters().get('country');






    if(firstName!=null && !firstName.equals('')){

     queryString+='and First_Name__c LIKE \''+String.escapeSingleQuotes(firstName)+'%\'';


    if(lastName!=null && !lastName.equals('')){

     queryString+='and Last_Name__c LIKE \''+String.escapeSingleQuotes(lastName)+'%\'';


    if(country!=null && !country.equals('')){

     queryString += ' and Country__c includes (\''+country+'\')';




  return null;



 public void executeQuery(){



  userDetails= Database.query(queryString);

  }catch(Exception e){








please help me to resolve this issue.



There are two problems that I can see.


Your button is making an ajax call, however it is not canceling the default behavior of the commandButton which is to submit the form.


Fix this with


<apex:commandButton onclick="scriptSearch();return false;" value="Search"/>



Also, your actionFunction needs to be configured to refresh your debug pageBlock after the ajax call is complete. Check out the reference for apex:actionFunction.


<apex:actionFunction name="searchCall" action="{!searchFunctionality}" rerender="debug">



You might also consider using the apex:actionStatus to show the status of the ajax call.




Thanks allot mark for giving me the clear information. Now i can able to get the values into my controller.


Thanks allot for your help. 





Would you mind marking my post as the solution?