NOTE: I'm guessing you know why adding a panel fixes the problem, but I'm including additional detail for the benefit of others who might encounter the same behavior.
Almost everything in XPages is processed hierarchically. So variables, data sources, and component references are often only valid within the context of a container.
Given the source code you listed in your question, the data source is attached to the "view root", so it's valid anywhere on that page (or Custom Control). As the page is evaluated at runtime, the root component will be processed first, and part of that evaluation is determining whether the data source attached to it needs to be created or already exists, based on its scope.
Once that's finished, it can start processing any child components, which -- again, in your example -- includes the jdbcConnectionManager
.
This is why, as Panu mentioned, the data source can't refer to the component: it's attached to a parent.
But data sources can be associated with specific panels, not just view roots. If you add a panel
as a sibling to the jdbcConnectionManager
-- specifically, below it -- and move the data source to that panel
, here's what then happens at runtime:
- Domino starts processing the view root; not much to do here now, so it just hands off control to its children.
- The first child is the
jdbcConnectionManager
, so whatever encoding needs to happen for that component occurs before dealing with the rest. - Next, the panel is evaluated. This includes evaluating the data source, which can now refer to the connection manager component, since it has already been loaded.
- Finally, all of the panel's descendant components (its children, their children, and so on) are evaluated. So anything that needs to refer to the data source does need to be defined somewhere inside this panel, but the data source can refer to the connection manager without blowing up specifically because that component isn't inside the panel... it's already been processed by the time the panel is dealt with.