[Seaside] Seaside2: separation between content and presentation
tblanchard@mac.com
seaside@lists.squeakfoundation.org
Tue, 3 Dec 2002 00:29:41 +0100
On Tuesday, December 3, 2002, at 12:13 AM, Avi Bryant wrote:
> Earlier versions of Seaside used a fairly similar model to WebObjects,
> but
> had what I called the "polymorphic subcomponent problem": how do you
> change the class of a subcomponent at runtime, based on, for example,
> the
> class of an entity object? It was this problem that I was getting at.
Right - you use WOSwitchComponent. WOSwitchComponent is a light
wrapper that has a binding for classname and forwards all bindings to
the wrapped component.
I just did an app that lets you build questionnaires on the web. So we
start out with the idea that a Questionnaire is an ordered list of
elements. Elements can be one of 4 things: Text, Divider, Question,
or Questionnaire. When you get to Question, we again have 4 types -
FreeFormText, SingleChoice (Radio Buttons), MultipleChoice
(Checkboxes), and FileUpload.
To render a questionnaire I have
GridLayout (essentially a table that can lay out horiz or vertically
depending on a setting)
Loop on elementList
ElementView - which is a switch component - class name is derived
from element.elementType
Depending on what type ElementView is - its just text, hr, the above
(recursive inclusion - which is expanded again), or for a question a
QuestionView.
QuestionView is itself a switchcomponent where the classname of the
component is derived from element.question.questionType. Its actually
very clean.
> In
> Seaside 0.94 you had to specify the class of the subcomponent in the
> bindings, just as you do below in WO. This meant that setting up even
> a
> simple tab control required tedious use of switch logic, and is IMO a
> serious flaw in the WO subcomponent system (but if there's a clean way
> around it I'd love to hear it).
WOSwitchComponent is pretty clean I think. I can't think of any better
way to do it in Seaside offhand. How would you do it?