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
Krishnan MishraKrishnan Mishra 

apex:actionSupport not working properly

In th following code the action support for my input text field is not working as it should work(Line number 69-70 in vf code).I want to navigate to the page number entered by the user.Following is my controller and VF code:
Code for controller
public class ContactListViewController {
    public ContactlistViewController(){
        system.debug('constructor first called');
        RecordsPerPageslist=10;
        allContactList = new list<wrapper>();
        for(contact c: (list<contact>)stdSetController.getRecords())
                allContactList.add(new wrapper(c));
        System.debug('constructor called');
    }
    Map<id,Boolean> m = new Map<id,boolean>();  	 // To store boolean values of checkboxes corrosponding to every contact id
    list<contact> con = [SELECT Name,id,Account.name,Title,Phone,Email FROM Contact];
    public list<wrapper> allContactList;			//Wrapper class object
    
    public list<wrapper> getWrapperContacts(){  	//List of wrapper class to display in table
        return allContactList;
    }
    
    public void getSelectedListContacts(){  		// Select contacts and save them in a map
        for(wrapper wc:allContactList){
            m.put(wc.con.id,wc.isSelected);
        }
        
        System.debug('getSelectedListContacts = '+m);
        
    }
    public void getSelectedAllContacts(){			//To select all contacts in a page
        for(wrapper wc:allContactList){
            m.put(wc.con.id,wc.isSelected=true);
        }
    }
    public void next(){
        System.debug('next');
		allContactList.clear();        
        this.stdSetController.next();
        for(contact c: (list<contact>)stdSetController.getRecords())
                allContactList.add(new wrapper(c)); 
        for(wrapper wc:allContactList){
            wc.isSelected=m.get(wc.con.id);
        }
    }
    public void previous(){
		allContactList.clear();        
        this.stdSetController.previous();
        for(contact c: (list<contact>)stdSetController.getRecords())
                allContactList.add(new wrapper(c)); 
        for(wrapper wc:allContactList){
            wc.isSelected=m.get(wc.con.id);
    }
    }
    public void last(){
        allContactList.clear();        
        this.stdSetController.last();
        for(contact c: (list<contact>)stdSetController.getRecords())
                allContactList.add(new wrapper(c)); 
        for(wrapper wc:allContactList){
            wc.isSelected=m.get(wc.con.id);
    }
    }
    public void first(){
        allContactList.clear();        
        this.stdSetController.first();
        for(contact c: (list<contact>)stdSetController.getRecords())
                allContactList.add(new wrapper(c)); 
        for(wrapper wc:allContactList){
            wc.isSelected=m.get(wc.con.id);
    }
    }
    public boolean getHasNext(){
        return stdSetController.getHasNext();
    }
    public boolean getHasPrevious(){
        return stdSetController.getHasPrevious();
    }
    public list<String> alphabet{
        get{															//To display a list of alphabets on vf page 
            alphabet = new list<string>{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','Others','All'};
       		return alphabet;	 
                }
        set;
    }
    public String alphaSearchConct{get;set;}							// To get commandlink parameter for alphabet selected
    public Pagereference getalphaSearch(){								//To update contact list as per the alphabet selected by the user
        allContactList.clear();
        if (alphaSearchConct=='All'){
            con = [SELECT name,Account.name,Title,Phone,Email FROM contact];
        }
        else{
            	con = [SELECT name,Account.name,Title,Phone,Email FROM contact WHERE lastName Like:alphaSearchConct+'%'];
        }
        ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(con);
        stdSetController= ssc;
        for(contact c: (list<contact>)stdSetController.getRecords())
                allContactList.add(new wrapper(c));
        system.debug('alphaSearchconct called');
        return null;
    }      
    public Integer PageNumber{
        get{                                                            //To get current page number
  		    System.debug('get of pageNumber called '+ PageNumber);
            this.PageNumber=stdSetController.getPageNumber();   
            return this.PageNumber;
        }
        set{  
            System.debug('set of pageNumber called');
           	this.pageNumber=value;         
    }
        }
    
    public PageReference NavigateByText(){
        
        System.debug('getNavigateByText '+ stdSetController.getPageNumber());
        allContactList.clear();
        this.stdSetController.setPageNumber(PageNumber);
            for(contact c:(list<contact>)stdSetController.getRecords())
                allContactList.add(new wrapper(c));
            //System.debug(stdSetController.getRecords());
           for(wrapper wc:allContactList){
            wc.isSelected=m.get(wc.con.id);
               System.debug(wc.isSelected);
               System.debug('pageNumber called');
               
    }
        return null;
    }
    public Integer TotalPages{                                            // Total number of pages as per user selection of Records per page
        get{
              if(stdSetController.getResultSize() <=10)
                   this.TotalPages=1;
              if(Math.Mod(stdSetController.getResultSize() ,stdSetController.getPageSize()) == 0)
                  this.TotalPages =(stdSetController.getResultSize()/stdSetController.getPageSize());
              else
                this.TotalPages = (stdSetController.getResultSize()/stdSetController.getPageSize())+1;
              //System.Debug(this.TotalPages);
                return totalpages;
        }
        set;
    }
    public Integer MaxNumberOfRecords{                                    //Maximum number of records in a query list
        get{
             return stdSetController.getRecords().size();
        }
        set;
    }
    public list<SelectOption> getRecordsPerPageOptionList(){              //To display a drop down list on vf page  
            list<SelectOption>  options = new list<SelectOption>();
            options.add(new selectOption('10','10'));
            options.add(new selectOption('25','25'));
            options.add(new selectOption('50','50'));
            options.add(new selectOption('100','100'));
            options.add(new selectOption('200','200'));
            return options;
    }
    public Integer RecordsPerPageslist{ 
        get;
        set{                                                          //To select number of records per page
            if(value!=null){
                this.RecordsPerPagesList=value;
                System.debug('RecordsPerPageList called');
            }
        }       
    }
    public Pagereference getChangeNumberOfRecordsPerPage(){
        allContactList.clear();
        for(contact c: (list<contact>)stdSetController.getRecords())
                allContactList.add(new wrapper(c)); 
         for(wrapper wc:allContactList)
            wc.isSelected=m.get(wc.con.id);
        return null;
    } 
    public ApexPages.StandardSetController stdSetController{            //Instantiating a standard set controller
        get{
            if(stdSetController==null){
             	 stdSetController = new ApexPages.StandardSetController(con);
            }
              stdSetController.setPageSize(RecordsPerPageslist);        //Limiting Number of records to be displayed per page 
            	System.debug('stdSetController called '+ stdSetController.getPageNumber());
            return stdSetController;   
        }
        set;
    }
    public class wrapper{
      public boolean isSelected{get;set;}
      public Contact con{get;set;}
       
         wrapper(contact con){
            isSelected = false;
            this.con = con;
        }
    }
}
Code for VF page:
<apex:page controller="ContactListViewController" sidebar="false">
    <apex:form >
        <!-- For alphabetic search-->
        <div align="right">
            <apex:panelGrid >
                <apex:repeat value="{!alphabet}" var="alph">
                    <apex:commandLink value="{!alph} | " action="{!getalphaSearch}" reRender="table">
                        <apex:param name="a" value="{!alph}" assignTo="{!alphaSearchConct}"/>
                    </apex:commandLink>
                </apex:repeat>
            </apex:panelGrid>
        </div>
        <apex:PageBlock id="table">
            <apex:pageMessages />
            <apex:commandButton action="{!getSelectedAllContacts}" value="Select All" reRender="table"/>
            <apex:PageBlockTable value="{!WrapperContacts}" var="contacts" >
                <!-- To display and select Checkboxes-->
                <apex:column >
                    <apex:facet name="header">
                    	<apex:inputCheckbox value="{!contacts.isSelected}">
                        	<apex:actionSupport event="onclick" action="{!getSelectedAllContacts}" reRender="table"/>
                        </apex:inputCheckbox>	
                        </apex:facet>
                    <apex:inputCheckbox value="{!contacts.isSelected}">
                        <apex:actionSupport event="onclick" action="{!getSelectedListContacts}" reRender="table"/>
                    </apex:inputCheckbox>  
                </apex:column>
                <!-- To Edit and Delete a record -->
                <apex:column headerValue="Action">
                    <apex:outputLink value="{!URLFOR($Action.Contact.Edit,contacts.con.id)}"> 
                        Edit |
                    </apex:outputlink>
                    <apex:outputLink value="{!URLFOR($Action.Contact.Delete,contacts.con.id)}"> 
                        Del |
                    </apex:outputlink>
                </apex:column>
                <apex:column headerValue="Name">
                    <apex:outputLink value="/{!contacts.con.id}">
                        {!contacts.con.name}
                    </apex:outputLink>
                </apex:column>
                <apex:column headerValue="Account Name">
                    <apex:outputLink value="/{!contacts.con.account.id}">
                        {!contacts.con.account.name}
                    </apex:outputLink>
                </apex:column>
                <apex:column value="{!contacts.con.Title}"/>
                <apex:column value="{!contacts.con.Phone}"/>
                <apex:column value="{!contacts.con.email}"/>
                <apex:inlineEditSupport />
            </apex:PageBlockTable>
      		</apex:PageBlock> 
        <!-- below code for pagination -->
        <apex:outputPanel id="button"> 
        <div align = "center" >
            <!-- To return to first page of records-->
            <apex:commandButton action="{!first}" value="<<" title="First Page" disabled="{!!HasPrevious}" reRender="table,button"/>
            <!-- To return to Previous page of records-->
            <apex:commandButton action="{!previous}" value="Previous" disabled="{!!HasPrevious}" reRender="table,button"/>
            <!-- To return to next page of records-->
            <apex:commandButton action="{!next}" value="Next >" disabled = "{!!HasNext}" reRender="table,button"/>
            <!-- To return to last page of records-->
            <apex:commandButton action="{!last}" value=">>" title="Last Page" disabled="{!!HasNext}" reRender="table,button"/>
            <!-- InputText to display current page and to navigate to any page number, At righmost side of page-->
            <span style="float:right">
                <apex:outputLabel value="Page ">
                </apex:outputLabel>
                 <!-- To navigate to the page--> 
                <apex:InputText value="{!PageNumber}" maxLength="4" size="1"/>
                <apex:actionSupport event="onchange" action="{!NavigateByText}" reRender="table,button"/>
                <!-- The above action support is not working-->         
                <apex:outputLabel value=" of {!TotalPages}">
                </apex:outputLabel>
            </span>
            <!-- To display a list for number of records to be selected per page-->
            <span style = "float:left">
                <apex:SelectList value="{!RecordsPerPageslist}" size="1" >
                    <apex:selectOptions value="{!RecordsPerPageOptionList}">    
                    </apex:selectOptions>
                    <apex:actionSupport event="onchange" action="{!getChangeNumberOfRecordsPerPage}" reRender="table,button"/>
                </apex:SelectList>
            </span>
        </div>
    </apex:outputPanel>      
    </apex:form>
</apex:page>


 
Gaurish Gopal GoelGaurish Gopal Goel
Hi, Please make this change in your code. Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it helps address your issue.​
<apex:InputText value="{!PageNumber}" maxLength="4" size="1">
<apex:actionSupport event="onchange" action="{!NavigateByText}" reRender="table,button"/>
</apex:inputText>
Krishnan MishraKrishnan Mishra
Hi Gaurish,
    Thanks for your support but the functionality is still not working