My question is continuation of this question
The problem I'm facing now is that when I click on the Next button its not showing the next page of set and I have 25 rows, I have setPageSize = 5
In the visualforce page i have action in the form like this:
<apex:page action="{!init}" ....
Apex code:
public List<ProductWrapper> Products
{
get
{
List<Product2> products2 = new List<Product2>();
list<ProductWrapper> pws = new list<ProductWrapper>();
for(Product2 p : (List<Product2>)this.con.getRecords()) {
if(p.Asset_Line_items__r.isEmpty()){
pws.add(New ProductWrapper(p,New Asset_Line_Item__c(Quantity__c = 0));
continue;
}
for(asset_line_items__c b : p.asset_line_items__r) {
//ProductWrapper pw = new ProductWrapper(p,b);
ProductWrapper pw = new ProductWrapper((Product2)p,b);
pws.add(pw);
}
}
Products2 = pws;
return Products2;
}
set;
}
Here is wrapper class:
public class ProductWrapper {
public Product2 product {get;set;}
public asset_line_items__c ali {get;set;}
public ProductWrapper(Product2 p, asset_line_items__c ali) {
product = p;
this.ali = ali;
}
}
Constructor:
public void init() {
this.con = new ApexPages.StandardSetController(SOQL);
this.con.setpageNumber(1);
this.con.setPageSize(5);
}
Pagination code:
public void first() {
con.first();
}
public void last() {
con.last();
}
public void previous() {
con.previous();
}
public void next() {
con.next();
}
public ApexPages.StandardSetController con;
public Boolean hasNext {
get {
return con.getHasNext();
}
set;
}
public Boolean hasPrevious {
get {
return con.getHasPrevious();
}
set;
}
public Integer pageNumber {
get {
return con.getPageNumber();
}
set;
}
public Integer totalPageNumber {
get {
Decimal totalSize = this.con.getResultSize();
Decimal pageSize = this.con.getPageSize();
Decimal pages = totalSize/pageSize;
return (Integer)pages.round(System.RoundingMode.CEILING);
}
set;
}
Visualforce page:
<apex:pageBlock id="pb">
<apex:pageBlockTable value="{!products}" var="a">
<apex:column headerValue="quantity" >
<apex:inputField value="{!a.ali.qty}" required="true" />
</apex:column>
<apex:column value="{!a.Name}" headerValue="Name"/>
<apex:column value="{!a.ProductName}" headerValue="P Name"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:outputPanel rendered="{!products.size>0}" styleClass="center">
<apex:commandButton value="|< First" action="{!first}" rerender="properties" rendered="{!HasPrevious}" />
<apex:commandButton value="Previous" action="{!previous}" rendered="{!HasPrevious}" rerender="properties"/>
Page {!pageNumber} of {!totalPageNumber}
<apex:commandButton value="Next" action="{!next}" rendered="{!HasNext}" rerender="properties"/>
<apex:commandButton value="Last>|" action="{!last}" rendered="{!HasNext}" rerender="properties" />
</apex:outputPanel>