I am using StandardSetController of the type QueryLocator for my solution. When I try to merge Save and Next together on Next button with Save being on action and next being on oncomplete JavaScript(executed through actionFunction), the button only executes once, the subsequent button press throws this exception on page "Modified rows exist in the records collection!". For Reference - if I keep next separate(no oncomplete script and action doing the next operation) then it works perfectly, but my requirement is merge them together. Here is the code(trimmed to show relevant parts):
Page:
<apex:page>
<apex:form id="TheForm">
<!-- search results table -->
<apex:pageBlock id="TablePanel">
<apex:pageblockButtons >
<apex:commandButton action="{!save}" value="Save Records" reRender="TablePanel"/>
</apex:pageblockButtons>
<div id="tableButtons">
<span class="page-buttons" style="float: left; margin-bottom: 5px;"> <apex:commandButton disabled="{!!StdSetControllerDetCen.hasprevious}" value="Previous" action="{!save}" rerender="TablePanel" oncomplete="onCompleteJSFunc2();"/>
**<apex:commandButton disabled="{!!StdSetControllerDetCen.hasnext}" value="Next"
action="{!save}" oncomplete="onCompleteJSFunc();" rerender="TablePanel"/>**
</span>
</div>
<!-- Account table -->
<apex:facet name="stop">
<apex:pageBlockTable value="{!DetailCensusList}" var="a">
<!-- bunch of columns with inputfields-->
</apex:pageBlock>
<apex:actionFunction name="NextPage" action="{!StdSetControllerDetCen.next}" reRender="TablePanel"/>
<apex:actionFunction name="PreviousPage" action="{!StdSetControllerDetCen.previous}" reRender="TablePanel"/>
</apex:form>
<script type="text/javascript">
function onCompleteJSFunc(){
NextPage();
}
function onCompleteJSFunc2(){
PreviousPage();
}
</script>
</apex:page>
Controller:
public with sharing class EmployeeWCPricingController {
// account and selection set/variables
public Integer PageNumber;
public EmployeeWCPricingController(ApexPages.StandardController controller){
DetCenList = new list<DCWrapperClass>();
if(allCensus.size() != 0)
Totalrecords = allCensus.size();
}
/***
* StdSetControllerDetCen - paging through the Account list
***/
public ApexPages.StandardSetController StdSetControllerDetCen {
get {
if(StdSetControllerDetCen == null) {
StdSetControllerDetCen = new ApexPages.StandardSetController(Database.getQueryLocator(QueryDetailCensus));
// sets the number of records in each page set
StdSetControllerDetCen.setPageSize(Integer.valueOf(RecPerPage));
PageNumber = StdSetControllerDetCen.getPageNumber();
}
return StdSetControllerDetCen ;
}
set;
}
/***
* getCurrentDetCenList - return an list for the table
***/
public list<DCWrapperClass> getDetailCensusList (){
System.debug('***Getdc1'+StdSetControllerDetCen);
UpdateDCSelectedSet();
System.debug('***Getdc2'+StdSetControllerDetCen);
DetCenList = new list<DCWrapperClass>();
for (APTS_LTC_Census__c a : (list<APTS_LTC_Census__c>)StdSetControllerDetCen.getRecords()){
DetCenList.add(new DCWrapperClass(a, DCSelectedSet.contains(a.Id)));
}
System.debug('***Getdc3'+StdSetControllerDetCen);
return DetCenList ;
}
public void save(){
StdSetControllerDetCen.save();
}
}