[Zope] Newbie Acquisition Question

Martijn Pieters mj@antraciet.nl
Tue, 19 Oct 1999 10:06:13 +0200


At 22:35 18/10/99 , James W. Howe wrote:
>I've been playing with Zope for a couple of days.  Coming from a Smalltalk 
>background, many of the concepts employed by Zope are very 
>familiar.  However, I seem to have a fundamental misunderstanding about 
>how acquisition works.  As an experiment, I created a Folder object called 
>"Testing".  I defined an index_html document with the following DTML code:
>
><dtml-var standard_html_header>
><dtml-var folderName>
><dtml-var standard_html_footer>
>
>I also defined a DTML method in Testing called "folderName" which 
>contained the following:
>
>Testing
>
>I viewed the page in a browser via http://localhost:8080/Testing and sure 
>enough I saw a page with the phrase "Testing" correctly displayed.  I then 
>created a Folder within Testing called "SubTest".  In SubTest, I defined 
>one DTML method called "folderName"  Inside of this method I put the contents:
>
>SubTest
>
>I then displayed the page via http://localhost:8080/Testing/SubTest and 
>was confused when the screen still displayed the phrase "Testing" instead 
>of "SubTest".  It's probably my Smalltalk bias, but I was expecting that 
>the system would look up the tree from SubTest until it found an 
>index_html that it could display.  Having found that, it would see that it 
>needed to execute the method "folderName".  Since the object being 
>displayed was SubTest, I assumed that it would try to find the 
>"folderName" method starting in SubTest.  Having found it, it would use 
>the result from that method for display.  However, this is not what 
>happened.  Where did I go wrong?  I was under the impression that I could 
>factor common behavior up the tree and only implement distinct behavior at 
>lower levels.  Did I just do something wrong?  Is there a way to 
>accomplish what I want to accomplish?

Acquisition does not always work as you'd first expect it to do. First of 
all, an acquired object, that accesses other attributes and objects itself, 
will do a lookup of those attributes and objects in its own context first. 
Your DTML Document index_html will therefore first look up folderName in 
its own context, which it will find there. This is something that tripped 
me up as well, even 6 months after first starting to look at Zope. Read the 
following document carefully, especially the bit about 'Acquiring Acquiring 
objects':

   http://www.digicool.com/releases/ExtensionClass/Acquisition.html

There is a solution to this: DTML _Methods_ (and SQL Methods) are seen as 
methods of their parent. This basically means that the acquisition search 
order doesn't start at themselves (like with DTML Documents), but at their 
parent object, _after acquisition_. So if you changed your index_html to a 
DTML Method, and called:

   http://localhost:8080/Testing/SubTest

Your index_html object would be acquired into SubTest, and called. It then 
starts to look up variables as if it where SubTest itself. It then will 
find folderName in Subtes, include it in the generated output, and, as 
expected, you'll get 'SubTest' returned to your browser.

--
Martijn Pieters, Web Developer
| Antraciet http://www.antraciet.nl
| Tel: +31-35-7502100 Fax: +31-35-7502111
| mailto:mj@antraciet.nl http://www.antraciet.nl/~mj
| PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149
------------------------------------------