You need to sign in to do that
Don't have an account?

Issue with Pagination for Wrapper Class
i have built a pagination for wrapper class,my requirement is after clicking the next link the previous link will activate , similarly when i will be on last page the next link will be deactivate.
my controller:-
public with sharing class acc_controller {
public List<Account> accList{get;set;}
public List<AccWrapper> accWrapList{get;set;}
public List<AccWrapper> accWrapList2{get;set;}
public List<AccWrapper> accWrapList3{get;set;}
//public Integer cust_limit{get;set;}
public Integer cust_offset{get;set;}
public Integer cust_fixed_offset{get;set;}
public Boolean showFinalResult{get;set;}
public Class AccWrapper
{
public Account acc{get;set;}
public Boolean flag{get;set;}
public AccWrapper(Account acc)
{
this.acc=acc;
this.flag=false;
}
}
public acc_controller(ApexPages.StandardController controller) {
//cust_limit=1;
showFinalResult=false;
cust_fixed_offset=2;
cust_offset=0;
accList=new List<Account>();
accWrapList=new List<AccWrapper>();
accWrapList2=new List<AccWrapper>();
accList=[select id,name from account limit 100];
Integer count=0;
for(Account accObj:accList)
{
accWrapList.add(new AccWrapper(accObj));
if(count<cust_fixed_offset)
{
accWrapList2.add(new AccWrapper(accObj));
count++;
}
}
}
public void saveList()
{
for(AccWrapper accWrapObj1:accWrapList)
{
for(AccWrapper accWrapObj2:accWrapList2)
{
if(accWrapObj2.acc.Id==accWrapObj1.acc.Id)
{
accWrapObj1.flag=accWrapObj2.flag;
}
}
}
}
public void next()
{
accWrapList2=new List<AccWrapper>();
cust_offset+=cust_fixed_offset;
if(cust_offset>accWrapList.size()-1)
{
cust_offset=accWrapList.size()-1;
}
Integer counter=0;
for(Integer i=cust_offset;i<accWrapList.size();i++)
{
if(counter<cust_fixed_offset)
{
accWrapList2.add(accWrapList[i]);
counter++;
}
else
{
break;
}
}
}
public void previous()
{
accWrapList2=new List<AccWrapper>();
cust_offset-=cust_fixed_offset;
if(cust_offset<1)
{
cust_offset=0;
}
Integer counter=0;
for(Integer i=cust_offset;i<accWrapList.size();i++)
{
if(counter<cust_fixed_offset)
{
accWrapList2.add(accWrapList[i]);
counter++;
}
else
{
break;
}
}
}
public void first()
{
}
public void last()
{
}
public void Process()
{
accWrapList3=new List<AccWrapper>();
for(AccWrapper accWrapObj1:accWrapList)
{
if(accWrapObj1.flag)
{
accWrapList3.add(accWrapObj1);
}
}
showFinalResult=true;
}
}
myVfpage:-
<apex:page standardController="Account" extensions="acc_controller">
<apex:form >
<apex:actionstatus startText="processing..." id="statusBar"></apex:actionstatus>
<apex:pageblock >
<!--<apex:commandLink value="First"/>-->
<apex:commandLink value="Next" reRender="pTable" status="statusBar" action="{!next}"/>
<apex:commandLink value="Previous" reRender="pTable" status="statusBar" action="{!previous}"/>
<!--<apex:commandLink value="Last"/> -->
<apex:commandbutton value="Process" action="{!Process}" rerender="finalResult" status="statusBar"/>
<apex:outputPanel id="pTable">
<apex:pageblockTable value="{!accWrapList2}" var="a" >
<apex:column headerValue="Select">
<apex:inputCheckbox value="{!a.flag}">
<apex:actionSupport event="onclick" rerender="pTable" status="statusBar" action="{!saveList}"/>
</apex:inputCheckbox>
</apex:column>
<apex:column value="{!a.acc.name}"/>
</apex:pageblockTable>
</apex:outputPanel>
<!--<apex:commandLink value="First"/>-->
<apex:commandLink value="Next" reRender="pTable" status="statusBar" action="{!next}"/>
<apex:commandLink value="Previous" reRender="pTable" status="statusBar" action="{!previous}"/>
<!--<apex:commandLink value="Last"/> -->
<apex:pageblock >
<apex:outputPanel id="finalResult">
<apex:pageBlockTable value="{!accWrapList3}" var="ac" rendered="{!showFinalResult}">
<apex:column value="{!ac.acc.name}"/>
</apex:pageBlockTable>
</apex:outputPanel>
</apex:pageblock>
</apex:pageblock>
</apex:form>
</apex:page>
please help me...
please run this code and please share the solution.
i am new to salesforce and this requirement is in high priority.
my controller:-
public with sharing class acc_controller {
public List<Account> accList{get;set;}
public List<AccWrapper> accWrapList{get;set;}
public List<AccWrapper> accWrapList2{get;set;}
public List<AccWrapper> accWrapList3{get;set;}
//public Integer cust_limit{get;set;}
public Integer cust_offset{get;set;}
public Integer cust_fixed_offset{get;set;}
public Boolean showFinalResult{get;set;}
public Class AccWrapper
{
public Account acc{get;set;}
public Boolean flag{get;set;}
public AccWrapper(Account acc)
{
this.acc=acc;
this.flag=false;
}
}
public acc_controller(ApexPages.StandardController controller) {
//cust_limit=1;
showFinalResult=false;
cust_fixed_offset=2;
cust_offset=0;
accList=new List<Account>();
accWrapList=new List<AccWrapper>();
accWrapList2=new List<AccWrapper>();
accList=[select id,name from account limit 100];
Integer count=0;
for(Account accObj:accList)
{
accWrapList.add(new AccWrapper(accObj));
if(count<cust_fixed_offset)
{
accWrapList2.add(new AccWrapper(accObj));
count++;
}
}
}
public void saveList()
{
for(AccWrapper accWrapObj1:accWrapList)
{
for(AccWrapper accWrapObj2:accWrapList2)
{
if(accWrapObj2.acc.Id==accWrapObj1.acc.Id)
{
accWrapObj1.flag=accWrapObj2.flag;
}
}
}
}
public void next()
{
accWrapList2=new List<AccWrapper>();
cust_offset+=cust_fixed_offset;
if(cust_offset>accWrapList.size()-1)
{
cust_offset=accWrapList.size()-1;
}
Integer counter=0;
for(Integer i=cust_offset;i<accWrapList.size();i++)
{
if(counter<cust_fixed_offset)
{
accWrapList2.add(accWrapList[i]);
counter++;
}
else
{
break;
}
}
}
public void previous()
{
accWrapList2=new List<AccWrapper>();
cust_offset-=cust_fixed_offset;
if(cust_offset<1)
{
cust_offset=0;
}
Integer counter=0;
for(Integer i=cust_offset;i<accWrapList.size();i++)
{
if(counter<cust_fixed_offset)
{
accWrapList2.add(accWrapList[i]);
counter++;
}
else
{
break;
}
}
}
public void first()
{
}
public void last()
{
}
public void Process()
{
accWrapList3=new List<AccWrapper>();
for(AccWrapper accWrapObj1:accWrapList)
{
if(accWrapObj1.flag)
{
accWrapList3.add(accWrapObj1);
}
}
showFinalResult=true;
}
}
myVfpage:-
<apex:page standardController="Account" extensions="acc_controller">
<apex:form >
<apex:actionstatus startText="processing..." id="statusBar"></apex:actionstatus>
<apex:pageblock >
<!--<apex:commandLink value="First"/>-->
<apex:commandLink value="Next" reRender="pTable" status="statusBar" action="{!next}"/>
<apex:commandLink value="Previous" reRender="pTable" status="statusBar" action="{!previous}"/>
<!--<apex:commandLink value="Last"/> -->
<apex:commandbutton value="Process" action="{!Process}" rerender="finalResult" status="statusBar"/>
<apex:outputPanel id="pTable">
<apex:pageblockTable value="{!accWrapList2}" var="a" >
<apex:column headerValue="Select">
<apex:inputCheckbox value="{!a.flag}">
<apex:actionSupport event="onclick" rerender="pTable" status="statusBar" action="{!saveList}"/>
</apex:inputCheckbox>
</apex:column>
<apex:column value="{!a.acc.name}"/>
</apex:pageblockTable>
</apex:outputPanel>
<!--<apex:commandLink value="First"/>-->
<apex:commandLink value="Next" reRender="pTable" status="statusBar" action="{!next}"/>
<apex:commandLink value="Previous" reRender="pTable" status="statusBar" action="{!previous}"/>
<!--<apex:commandLink value="Last"/> -->
<apex:pageblock >
<apex:outputPanel id="finalResult">
<apex:pageBlockTable value="{!accWrapList3}" var="ac" rendered="{!showFinalResult}">
<apex:column value="{!ac.acc.name}"/>
</apex:pageBlockTable>
</apex:outputPanel>
</apex:pageblock>
</apex:pageblock>
</apex:form>
</apex:page>
please help me...
please run this code and please share the solution.
i am new to salesforce and this requirement is in high priority.
All Answers
https://hisrinu.wordpress.com/2012/01/09/pagination-using-standardsetcontroller/
blog.jeffdouglas.com/2009/07/14/visualforce-page-with-pagination/
thank you so much. the code is working according to my requirement..
but one more thing , when i click the "Processed" button, its showing me the selected records, at the same time i want to refresh the checkbox table, which is not occuring now.
how i will do this?
i have used the above code, but i have some requirement like-
Implement functionality where we can give user an option to select No of records he wants to view on one Page . Options (5 ,7, 10) and accordingly the links (Next , previous) should be enabled for the User. how i will do that?
please help
please help..
Implement this code.
Could you please mark it as best answer it you found it helpful!
Could you please mark it as best answer it you found it helpful!
thank you so much..
but if i am selecting 5 records by clicking checkbox, and then when i am clicking on Processed button. its only showing me 1 record but i want to see all the checked record..
how i will do that...
it was worked in my code which i have posted. when i added your code the dropdown is working,but the Processed button function is not working.
what is the solution...?
<apex:page controller="ContactsTable1" sidebar="false" showHeader="false">
<apex:form id="myform">
<apex:pageblock id="pbId" >
<apex:pageBlockSection columns="1" >
<apex:pageblock >
<!-- In our table, we are displaying the Contact records -->
<apex:pageblockButtons location="Top">
<apex:commandButton value="Processed" action="{!clickMe}" />
</apex:pageblockButtons>
<apex:pageblocktable value="{!Contact}" var="cc" id="test" >
<apex:column headerValue="Choose Contact">
<apex:inputCheckbox value="{!cc.bool}"/> </apex:column>
<apex:column value="{!cc.con.Name}"/>
<apex:column value="{!cc.con.Email}"/>
</apex:pageblocktable>
<apex:pageBlockButtons location="Bottom">
<apex:commandButton value="First" action="{!Setcon.First}" disabled="{!NOT(Setcon.hasPrevious)}" reRender="myform" />
<apex:commandButton value="Previous" action="{!Setcon.Previous}" disabled="{!NOT(Setcon.hasPrevious)}" reRender="myform" />
<apex:commandButton value="Next" action="{!Setcon.Next}" disabled="{!NOT(Setcon.hasNext)}" reRender="myform" />
<apex:commandButton value="Last" action="{!Setcon.Last}" disabled="{!NOT(Setcon.hasNext)}" reRender="myform" />
</apex:pageBlockButtons>
<apex:actionFunction name="refreshPageSize" action="{!refreshPageSize}" status="fetchStatus" reRender="pbId"/>
<apex:selectList value="{!size}" multiselect="false" size="1" onchange="refreshPageSize();">
<apex:selectOptions value="{!ContactsTables}"/>
</apex:selectList>
</apex:pageblock>
<apex:pageBlock >
<apex:outputPanel rendered="{!display}">
<apex:pageblocktable value="{!selectedList}" var="w" rows="1" columns="2" >
<apex:column value="{!w.Name}"/>
<apex:column value="{!w.Email}"/>
</apex:pageblocktable>
</apex:outputPanel>
</apex:pageblock>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
controller:-
//Controller
Public class ContactsTable1{
//public String size { get; set; }
public Integer size { get; set; }
Public List<WrapperContactWrapper> wrapperlist;
Public Integer noOfRecords{get; set;}
Map <id,Contact> SelectedcontactMap = new Map <id,Contact>();
public boolean display{get;set;}
public list<Contact> selectedList {get;set;}
public List<SelectOption> ContactsTables{get;set;}
Public class WrapperContactWrapper {
Public Contact con{get;set;}
Public boolean bool{get;set;}
public WrapperContactWrapper(Contact c,boolean bool) {
this.con = c;
this.bool = bool;
}
}
public ContactsTable1 (){
size=10;
ContactsTables= new List<SelectOption>();
ContactsTables.add(new SelectOption('5','5'));
ContactsTables.add(new SelectOption('10','10'));
ContactsTables.add(new SelectOption('20','20'));
ContactsTables.add(new SelectOption('50','50'));
ContactsTables.add(new SelectOption('100','100'));
}
public ApexPages.StandardSetController Setcon {
get { if(Setcon == Null) {
Setcon = new ApexPages.StandardSetController(Database.getQueryLocator([Select Name,Accountid,Email,MobilePhone,LeadSource from Contact]));
setCon.setpagesize(size);
noOfRecords = setCon.getResultSize(); }
return Setcon;
}
set;
}
public PageReference refreshPageSize() {
Setcon.setPageSize(size);
return null;
}
Public List<WrapperContactWrapper> getContact() {
getSelectedContact();
wrapperlist = new List <WrapperContactWrapper>();
for(Contact cc : (List<contact>)Setcon.getRecords()) {
if( SelectedcontactMap .ContainsKey(cc.id)) {
wrapperlist.add (new WrapperContactWrapper(cc,true));
} else {
wrapperlist.add(new WrapperContactWrapper(cc,false));
}
}
return wrapperlist;
}
public void getSelectedContact(){
if(wrapperlist!=null) {
for(WrapperContactWrapper wr:wrapperlist) {
if(wr.bool == true) {
SelectedcontactMap.put(wr.con.id,wr.con);
} else {
SelectedcontactMap.remove(wr.con.id);
System.debug('@@@123'+SelectedcontactMap);
}
}
}
}
/*public void clickMe() {
display = true;
getSelectedContact();
selectedList = SelectedcontactMap.values();
}*/
public void clickMe() {
display = true;
getSelectedContact();
selectedList = SelectedcontactMap.values();
wrapperlist = null;
SelectedcontactMap.clear();
getContact();
}
public integer pageNumber {
get {
return Setcon.getPageNumber();
}
set;
}
}
Remove Row="1"
please mark it as best answer it you found it helpful!
now it is working..
please mark it as best answer it because other use this code !!!
Thanks