[Zope] Selection Box

Ian Blenke icblenke@2c2.com
Mon, 18 Oct 1999 22:32:18 -0400


On Tue, Oct 19, 1999, John Glossner wrote:

> I have searched most reference material with no avail to try 
> to find out how to set up a simple selection box.
> 
> I have a ZClass called LinkClassification to which I have attached
> a property link_class which is assigned to value link_class_data.
> 
> My question is where do I create the variable link_class_data?
> I think it should be as another property in the same directory.
> When I do this the zope management screen hangs.

link_class_data must be in the appropriate namespace to be visible
to the propertysheet. 

 1. Define it as a "lines" Property

 2. Define it as a method that returns an array of items, ie:
	<dtml-return "('Option 1','Option 2')">

 3. Define it as a TinyTable, with one column name: "sequence-item"

If you add these lists to the Product containing your ZClass, then
the propertysheet for an instanciated object of the ZClass will
give you errors when it shows up.

So you copy the lists inside of your ZClass definition. The
downside is apparent: every object now has a copy of all of your
lists. Big bummer when it comes to long lists of items or a 
large number of objects.

But, the real problem comes when you try to create an instance
of your ZClass outside of the management UI. This is a battle
that I'm still loosing (even using KMnetNews as an example). :(

> I presume this is because I did not define the link_class_data
> property correctly. What are the valid types allowed for
> a selection box - strings,text,etc.?

It must be a list.
 - more importantly: it must be a list that implements
   sequence-item when iterated through (if you use a 
   TinyTable without naming your column as "sequence-item",
   you get odd results :)

It must be in a variable (it can't be an expression).
 - this breaks using objectValues() or something similar

It must be relative (you cannot fully qualify it "with.a.path").
 - this breaks "globalizing" lists into a Product namespace

> Does someone have the syntax for how the selection box is
> assigned a variable? Or is there an example somewhere I 
> can reference?

This is the real pain. In order to draw a selection box that
has a specific variable selected, you need to have a massive
hunk 'o code in a loop to compare every option to the selected
value. If a value is selected, then you put the "SELECTED"
keyword in the OPTION tag. ARGH.

There has to be an easier way. I'm beginning to think that
a "Utils" folder with common "tag renderers" would be alot
easier than the mess I've been stumbling through for the past
3 days.

DTML is difficult. Coding ZClasses purely in DTML is a nasty
experience if you want to do anything useful with the
resulting objects outside of the management interface.

- Ian "DTML-has-made-me-a-bitter-man" Blenke <ian@blenke.com>