You need to sign in to do that
Don't have an account?
Alex Yhap
Update a non Sobject List from Apex class
I have a dropbox of numbers of records per page. When I select a value the assignPerPage PageReference method is called. If you look at the Visualforce page code, the apex:pageBlockTable calls the currentPage List<wrapPayment>. The desired outcome is when the assignPerPage is changed the pageBlockTable is to be updated, changing the pageSize from 10 to whatever is selected.
My question is how would I update the list or reevaluate the list to output the correct number of records per page.
My question is how would I update the list or reevaluate the list to output the correct number of records per page.
<apex:tab label="To Be Claimed" name="name1" id="tabOne"> <apex:pageMessages /> <apex:form> <apex:pageBlock id="toBeID" title="Balance: £{!sumToBeClaimed}" > <apex:pageBlockButtons location="top"> <apex:commandButton value="Process Selected" action="{!processSelected}" style="float:right;" rendered="{!IF(toBeTotalRecs==0,false,true)}"/> </apex:pageBlockButtons> <apex:pageBlock> <div style="display:inline;"> <apex:outputText value=" {!pageNumber * pageSize} - {!(pageNumber * pageSize) + pageSize} of {!toBeTotalRecs} Results"/> </div> <div style="display:inline; float:right;"> Results per page: <apex:selectList value="{!perPageSelection}" size="1"> <apex:selectOptions value="{!perPageNumbers}"></apex:selectOptions> <apex:actionSupport event="onchange" action="{!assignPerPage}" reRender="toBeID"/> </apex:selectList> </div> </apex:pageBlock> <apex:pageBlockTable value="{!currentPage}" var="claimed" id="theaddrs" styleClass="tablesorter" headerClass="header"> <apex:column > <apex:facet name="header"> <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/> </apex:facet> <apex:inputCheckbox id="inputId" value="{!claimed.selected}"/> </apex:column> <div id="{!claimed.pay.Id}"> <apex:column headerValue="Payment No"> <apex:outputLink value="{!$Site.Domain}/{!claimed.pay.Id}">{!claimed.pay.Name}</apex:outputLink> </apex:column> <apex:column value="{!claimed.pay.causeview__Constituent__c}" headerValue="Donor"/> <apex:column value="{!claimed.pay.causeview__Date__c}" headerValue="Gift Date" styleClass="header"/> <apex:column value="{!claimed.pay.Gift_Aid_Amount__c}" headerValue="Gift-Aid Amount"/> <apex:column value="{!claimed.pay.Gift_Aid_Declaration__c}" headerValue="Gif-Aid Declaration"/> </div> </apex:pageBlockTable> <apex:pageBlockButtons location="bottom" rendered="{!IF(toBeTotalRecs==0,false,true)}"> <apex:commandButton value="First" action="{!first}" rendered="{!isFirst}" rerender="toBeID"/> <apex:commandButton value="Previous" action="{!previousPage}" rendered="{!hasPrevious}" rerender="toBeID"/> <apex:commandButton value="Process Selected" action="{!processSelected}" rendered="false" rerender="toBeID"/> <apex:commandButton value="Next" action="{!nextPage}" rendered="{!hasNext}" rerender="toBeID"/> <apex:commandButton value="Last" action="{!last}" rendered="{!isLast}" rerender="toBeID"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:tab>
public Integer pageSize { get; set; } public List<wrapPayment> wrapPaymentList // Our collection of the class/wrapper objects wrapPayment { get { if ( wrapPaymentList == null ) { wrapPaymentList = new List<wrapPayment>(); //for ( causeview__Payment__c p : [SELECT Id, causeview__Constituent__c, Gift_Aid_Declaration__c, Name, causeview__Date__c, Gift_Aid_Amount__c, Gift_Aid_Claim_Status__c FROM causeview__Payment__c WHERE Gift_Aid_Claim_Status__c = 'Not claimed' AND Gift_Aid_Elegible__c = true ORDER BY causeview__Date__c DESC] ) for ( causeview__Payment__c p : [SELECT ID, Name, Gift_Aid_Claim_Status__c, House_Number__c, First_Name__c, Last_Name__c, Postal_Code__c, causeview__Constituent__c, Gift_Aid_Declaration__c, causeview__Date__c, Gift_Aid_Amount__c FROM causeview__Payment__c WHERE Gift_Aid_Claim_Status__c = 'Not claimed' AND Gift_Aid_Elegible__c = true ORDER BY causeview__Date__c DESC] ) { // As each contact is processed we create a new cContact object // and add it to the contactList wrapPaymentList.add( new wrapPayment( p ) ); } } return wrapPaymentList; } private set; } public Integer pageNumber { get; set; } public Integer numberOfPages { get; set; } private List<List<wrapPayment>> list_Pages { get { if ( list_Pages == null ) { list_Pages = new List<List<wrapPayment>>(); Integer numInPage = pageSize; List<wrapPayment> thePage; if(wrapPaymentList.size() > 0) { for ( wrapPayment pPay : wrapPaymentList ) { if ( numInPage >= pageSize ) { thePage = new List<wrapPayment>(); list_Pages.add( thePage ); numInPage = 0; } thePage.add( pPay ); numInPage++; } } } if(list_Pages.size() >0){numberOfPages = list_Pages.size() - 1;} System.Debug('list_Pages: '+list_Pages); return list_Pages; } private set; } public List<wrapPayment> currentPage { get { If(list_Pages!=null && list_Pages.size() > 0){ return list_Pages[ pageNumber ]; } else{ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,'No record to be claimed.'); ApexPages.addMessage(myMsg); return null; } }} public PageReference assignPerPage() { pageSize = perPageSelection; return null; }
the solution was to simply null the List holding the data, that would then reevalutae the List.
pcon - thanks for your help!
All Answers
I set this value in the default constructor...is this best practice?
When you change your selectList and pick a new number (let's say 25) the page size will be stored in that variable. You are using a different variable pageSize to determine the number of results to return. You should get the Integer.valueOf your perPageSelection variable and either store that in pageSize or just discard pageSize completely and only use the Integer.valueOf the perPageSelection variable everywhere. You will need to cast it to a String in your constructor to set the default however.
the solution was to simply null the List holding the data, that would then reevalutae the List.
pcon - thanks for your help!