I am assigning controller properties with some value in its constructor. I am using <apex:actionPoller />
on VF page and it is rerendering some part of visualforce page section. But it not retaining the value of controller properties.
VF Code:
<apex:form >
<apex:actionPoller action="{!incrementCounter}" reRender="RecTypeCount" interval="20"/>
<apex:pageBlock title="Select Object" id="pbselobj">
<apex:pageblocksection columns="1" id="pbsecselobj">
<apex:commandbutton action="{!fetchdata}" value="show Data" immediate="true"/>
</apex:pageblocksection>
</apex:pageBlock>
<apex:outputPanel id="RecTypeCount">
--{!mdata}--{!test}
<apex:outputText value="Watch this counter: {!count}" id="counter"/>
<apex:pageBlock title="First Name Last Name" >
<apex:pageBlockTable value="{!mdata}" var="rt1" style="width: 50%;" >
<apex:column headerValue="First Name" value="{!rt1}" style="padding-left: 5px;" >
</apex:column>
<apex:column headerValue="Last Name" value="{!mdata[rt1]}" style="padding-right: 5px; text-align: right;" >
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
Batch Class Code:
global class TestBatchClassCallingApexClass implements Database.Batchable < sObject >, Database.stateful {
private List<String> aList = null;
private Integer currentIndex;
private Map<String,String> mapName;
global Database.QueryLocator start(Database.BatchableContext bc){
String query = 'SELECT Id,Name FROM Account';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc, List<sObject> records){
// process each batch of records
}
global void finish(Database.BatchableContext bc){
// execute any post-processing operations
//
mapName = new Map<string, string>();
mapName.put('John','Mathew');
mapName.put('James', 'Bond');
ApexClassCalledByBatch objApx = new ApexClassCalledByBatch();
objApx.mapValuedata(mapName);
}
}
Apex Controller Code:
public class ApexClassCalledByBatch {
public Map<string, string> mapName {get;set;}
public Map<string, string> varName {get;set;}
public Map<string, string> mnew;
public String test {get;set;}
public Integer count = 0;
public ApexClassCalledByBatch(){
test ='Hello';
system.debug('null constructor called');
mnew = new Map<string, string>();
}
/*public ApexClassCalledByBatch(Map<string,string> mapName){
system.debug('mapname status :: ' + mapName);
mnew = new Map<string, string>();
test ='Hello1';
if (mapName == null){
this.mapName = mapName;
}
else
{
mapName = mapName;
}
system.debug('mapName' + mapName.keyset());
mnew = mapName;
Mdata(mapName);
system.debug(' wow ');
}*/
public void mapValuedata(Map<string,string> mapName) {
varName = mapName;
mnew = mapName;
system.debug('varName :: ' + varName);
}
public Map<string,string> getMdata() {
return varName;
}
public pagereference showData(){
Pagereference pf = new PageReference('/apex/BatchVFPage');
pf.setRedirect(true);
return pf;
}
public void fetchdata(){
system.debug('batch class called');
TestBatchClassCallingApexClass objTBCAC = new TestBatchClassCallingApexClass();
ID batchprocessid = Database.executeBatch(objTBCAC,200);
}
public PageReference incrementCounter() {
// system.debug('mapName value after refresh through action poller' + mapName.keyset());
count++;
varName = getMdata();
system.debug(mnew +' woow '+varName);
test ='Hello'+count;
return null;
}
public Integer getCount() {
return count;
}
}