[SalesForce] ActionPoller and pageMessages rerender issue

I have a pretty batch that is trigger from a VF page. Then I check the batch status using an ActionPoller until it is completed and finally I rerender the batch results.

Everything is working fine but the pageMessages rerender. I can't figure out why.

I could check that the msgPanel is rerendering ok using the NOW. But the ApexPage.Messages is empty.

My VF looks like this:

<apex:outputPanel id="msgPanel">
      <apex:pageMessages id="msg"/>

 <apex:actionPoller interval="5" action="{!checkBatchStatus}" enabled="{!batchStatus}" onsubmit="console.log('checking..');" oncomplete="{!batchComplete}&&refreshJS();" />

<apex:actionFunction action="{!refreshGenerate}" name="refreshJS" reRender="msgPanel,resultsPanel" /> 

In the controller I have this:

public PageReference checkBatchStatus(){

            AsyncApexJob job    =   [select........1];
        if(job.Status == 'Completed'){

            ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.CONFIRM ,
             currentBatch+' Completed. '));
            //some internal checks
                    ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR ,errorDescription);

            batchComplete = true;
            batchStatus = false;

         batchStatus = true;
  return null;
   public void refreshGenerate(){ 
      // empty method, it is just used by javascript to trigger some rerenders.

Is this a rerender bug of salesforce ?

Please help

Best Answer

It seems that the pageMessages behave a bit like a transient variable. Since you rerender the pageMessages element in another request (the actionFunction, rather than the actionPoller), the values are resetted. I haven't confirmed this yet.

If you move the rerender of the pageMessages element as a part of the actionPoller it will work.

Related Topic