+ Start a Discussion
App_Dev1App_Dev1 

Controllers in compositions

Is it possible to use multiple controllers in a composition?

In the example from p. 92 of the doc:

<apex:page>
<apex:composition template="composition">
<apex:define name="header">(page) This is the header of mypage</apex:define>
<apex:define name="body">(page) This is the body of mypage</apex:define>
</apex:composition>
</apex:page>

What is the behavior when my header page uses controller A and body uses B?

What I'm seeing now is that the last referenced controller "wins" and becomes the controller for the whole page. I think this also happens with includes.

IMHO the composition is already powerful for building reusable visual components, but would be even more so if each define block had completely independent state/logic.

dchasmandchasman
There are some issues (as you have found out yourself) with Winter '08 and composition/includes w.r.t. controller scope. I spent quite a bit of time in Salesforce.com Spring '08 - just around the corner - fixing these scoping issues. In Spring '08 each page that uses a unique combination of controller/extensions gets its own controller scope and any pages involved in a composition or include will share the same physical controller instance if and only if they use the same controller|standardController and extensions values (this lets you share when you want to).

Also, we are deprecating <apex:include> - this will be replaced by the significantly more powerful and elegant custom component feature in Spring '08. One major shortcoming of <apex:include> is data passing from the container page to the included page. This is completely addressed by custom components by providing the ability to define a component's attributes, data types for those attributes, requiredness, etc...



Message Edited by dchasman on 12-25-2007 02:06 PM