[SalesForce] Displaying messages on redirected VF page

This is roughly the same question as in here, I can't comment so I'm re-asking.

My problem is that if the redirect is created in the method assigned to apex:page action attribute, the messages are still lost. I.e.

page 1:

<apex:page controller="aaTest" action="{!processtempcon}">
  <apex:form>
    <apex:commandButton action="{!processtempcon}" value="Reload"/>
  </apex:form>
</apex:page>

page 2 (helloworld2):

<apex:page controller="aaTest">
  <apex:messages />
  <apex:outputText value="{!myint}" />
</apex:page>

controller (aaTest):

public with sharing class aaTest{       
 public Integer myInt { get; set; }    
 public aaTest(){ myInt = 4; }

 public pagereference processtempcon(){
    pagereference p = page.helloworld2;
    apexpages.Message msg = 
      new Apexpages.Message(ApexPages.Severity.Info,'Total Number of reloads: ' + (myInt++));
    apexpages.addmessage(msg);
    return p; 
  }
}

So when I open the first page, it is correctly redirected to page 2 and the output is just "5". If I remove an action attribute in the first page and click a button, I would see a message as well as "5".

What am I missing?

Cheers

looks like nobody knows the answer

Best Answer

The two pages share the controller class aaTest so fields are preserved via view state between the two pages. (This approach is commonly used for wizards.)

So whichever way processtempcon is invoked, the increment of myInt done via page 1 is preserved and presented in page 2.

(I'm answering what I think is your question of behaviour you don't expect when you remove setRedirect(true). If you can't comment or edit your question we are a bit stuck on you providing feedback if my assumption is wrong...)