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;
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'};
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
System.debug('wrapperContacts called');
return allContactList;
}
public void SelectedListContacts(){ // Select contacts and save them in a map
System.debug('SelectedListContacts called');
for(wrapper wc:allContactList){
m.put(wc.con.id,wc.isSelected);
}
//System.debug('getSelectedListContacts = '+m);
}
public void SelectedAllContacts(){ //To select all contacts in a page
System.debug('SelectedAllContacts called');
for(wrapper wc:allContactList){
m.put(wc.con.id,wc.isSelected=true);
}
}
public void next(){
System.debug('next called');
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(){
System.debug('previous called');
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(){
System.debug('last called');
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(){
System.debug('first called');
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(){
System.debug('getHasNext called');
return stdSetController.getHasNext();
}
public boolean getHasPrevious(){
System.debug('getHasPrevious called');
return stdSetController.getHasPrevious();
}
public list<String> alphabet{get;set;}
public String alphaSearchConct{get;set;} // To get commandlink parameter for alphabet selected
public Pagereference alphaSearch(){ //To update contact list as per the alphabet selected by the user
System.debug('alphaSearch called');
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 ');
allContactList.clear();
this.stdSetController.setPageNumber(PageNumber);
//System.debug('getNavigateByText '+ stdSetController.getPageNumber()+'records are '+ stdSetController.getRecords());
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);
}
return null;
}
public Integer TotalPages{ // Total number of pages as per user selection of Records per page
get{
System.debug(TotalPages);
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 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 ChangeNumberOfRecordsPerPage(){
System.debug('ChangeNumberOfRecordsPerPage called');
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 ');
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:param value="{!contacts.isSelected}" assignTo="{!Allselection}"/>
</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"/>
</apex:InputText>
<!-- 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>