Dynamic Web Development with Seaside

26.8Custom Descriptions

In some cases it might happen that there is no description provided to use with a class. If your domain manipulates money (amount and currency) or URLs (scheme, domain, port, path, parameters) you may want to define your own descriptions (or load an extension package that already provides these descriptions) to take advantage of Magritte.

Extending Magritte is simple, create your own description but remember that Magritte is described within itself so you have to provide certain information.

  • Create a subclass of MAElementDescription.
  • On the class-side override: isAbstract to return false, label to return the name of the description. On the instance-side override: kind to return the base-class, acceptMagritte: to enable visiting and validateSpecific: to validate.
  • Create a view, if you want to use it for UI building.

We suggest you have a look at existing descriptions. In addition, carefully choosing the right superclass can already provide you part of what you are looking for. Parsing, printing and (de)serialization is implemented by the following visitors: MAStringReader, MAStringWriter, MABinaryReader and MABinaryWriter.

Copyright © 19 March 2024 Stéphane Ducasse, Lukas Renggli, C. David Shaffer, Rick Zaccone
This book is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 license.

This book is published using Seaside, Magritte and the Pier book publishing engine.