[Zope3-dev] Should containers tell you if they accept empty string keys?

Steve Alexander steve@cat-box.net
Mon, 18 Nov 2002 15:24:29 +0000


When you call setObject on a container, you must provide string to use 
as a key. Depending on the implementation, a container can:

* Use the key you provided

* Use some modified form of the key you provided

* Ignore the key you provided, and generate its own key

The return value of setObject is the key the container used.

A common protocol is to

* Use the key provided, unless it is an empty string, in which case
   generate a key

An empty string is not a valid value for the key of a container. So, if 
a container accepts an empty string as a key, it must provide its own key.


Short of actually trying to add an object using an empty string key, 
there is in general no way of knowing if a container accepts 
empty-string keys.

This causes a problem with adding views that have several pages 
presented in sequence: the "no name provided" error only comes up after 
the last page, when the user has already done some work, and when it is 
too late to correct the problem.

Solution:

Either of the following approaches would solve the problem.

* The first page of a multi-page adding view needs to check that 
contentName is set on the Adder.

   - This introduces a coupling between adder views and the
     implementation of the container that is being added to.


* There is some way of checking whether the container supports empty 
string keys before actually adding an object, so that the UI can be 
presented appropriately.

   - This makes the IWriteContainer interface slightly more complex.


I favour the latter approach, as I really don't like the coupling 
implied by the former.

--
Steve Alexander