[Seaside] Seaside best practices (part 2)

Diego Lont diego.lont at delware.nl
Tue Feb 12 15:35:41 UTC 2013

> Also a lot of features are implemented using "monkey patching". The most known is the asComponent, that is implemented in Object.
> Personally I am not a fan of monkey patching, but using Magritte will force you into monkey patching the Magritte classes. You will need custom properties, if you want to do some more advanced stuff with Magritte. Inheriting is not really recommended, as you will need to inherit from all types to do so.

These features allow for a very powerful way of modifying Magritte, without actually needing to change Magritte itself. For instance I have made groups "collapsable" and "ajax aware". When clicking on the title, it only displays the title. And on each change in the group, it re-renders the group, so that dependent values also update (*). I.e. when you change a customer, the list of possible addresses also changes. This is done by only adding a few methods:
First I have set a custom form renderer (see part 1) for all objects. In this form renderer I implemented the 
	renderElement: aDescription
In this method I use quite a lot of other methods as well, since this one is a bit complex. First of all I check if it is a group, if so, I delay the rendering until the group is finished. In the group I generate a update script that re-renders the entire group when necessary and in the end I call the method:
	renderContentOn: ajaxScript:
This method did not exist, but I added this method to the MADescriptionComponent, and the MAElementComponent. It adds the ajaxScript as a parameter, allowing the different input types to couple this script on the correct event.

This way I stay compatible with future updates of Magritte (I did not change any code, I only added), and have added some advanced features.

Finally I would like to end with the remark that Magritte focusses on static descriptions. Although the update from Magritte 2 to Magritte 3 allows for descriptions that depend on the state of the object, the description is still very inflexible for changes. Current components are not updated when you change the description. And the description is not updated when you change the value in the memento.

(*) Note that this implies that you need to change the values in the memento on an update. This was not a trivial exercise.

More information about the seaside mailing list