[SalesForce] Pass parameter froma visual force page to another visual force page included in the same page

I have a visual force page that is invoked on a custom button on opportunity detail page. I wanted to include another page to display some custom data to this visual force page .
How do I pass a custom variable on opportunity to the controller of the page included?
I wanted to display results on the included page when the main page is rendered.

main page:

<apex:page standardController="opportunity" extensions="CMEditController">
<apex:form >
<apex:outputPanel id="errorMessagespanel" >
<apex:pageMessages ></apex:pageMessages> </apex:outputPanel>

<apex:pageBlockSection title="Call Outcome Details" columns="2">
<apex:inputField value="{!opportunity.LeadSource}"/> 
</apex:pageBlockSection>

<apex:pageBlockButtons location="Bottom">
<apex:commandButton action="{!saveandclose}" value="Save"  rerender="errorMessagespanel"/>
<apex:commandButton action="{!cancel}" value="Cancel" onclick="window.top.close()"/>
</apex:pageBlockButtons>
</apex:pageBlock>
<apex:pageBlock >

<apex:include pageName="displayNotes"/>

</apex:pageBlock>
</apex:form>
</apex:page>

included page :

<apex:page Controller="NotesController" tabStyle="note">

    <apex:dataTable value="{!notesList}" var="note" cellspacing="5">
   <apex:column >
     <apex:facet name="header">Note</apex:facet>
     <DIV style= "width:100%;overflow:hidden;word-wrap:break-word">

   <apex:outputText value="{!note.noteText}"/>   
</DIV>   </apex:column>   

          </apex:dataTable>
</apex:page>

Notes Controller needs a custom field data from opportunity to query Notes to be displayed.

Best Answer

<apex:include> seems to be pretty limited in terms of what it supports. I assume the two pages get built together in the same context, so one method of transferring data would be to use some static variables in one of the controllers or a third class. You could set the variables in the primary controller and read them in the other, though you'd probably need to do it in the constructor and you could still potentially get caught out by the order of execution.

If you want to step it up a little, there are also ways to hook up two controllers so that they can call methods on each other via the use of a common base class, you can find more information on that on developer.salesforce.com.

Related Topic