Ok, this seems to work, slight modification from yours
to prevent
the cascade accessor from being added more than once, otherwise
every render built up long chains of cascading accessors, does this
seem right? Also, any way to add a label or something to each
group of fields?
Aha, I see the problem. Sorry, I didn't think that far in my first
example. It would be probably easier to copy the descriptions before
modifying them:
orderView := (anOrder description ***copy***
addAll: (anOrder billingAddress description collect: [ :each |
each ***copy*** accessor: (MACascadeAccessor
accessor: (MASelectorAccessor selector: #billingAddress)
next: each accessor) ]);
addAll: (anOrder shippingAddress description collect: [ :each |
each ***copy*** accessor: (MACascadeAccessor
accessor: (MASelectorAccessor selector: #shippingAddress)
next: each accessor) ]);
asComponentOn: anOrder) addValidatedForm: #(#update #cancel ).
I see that this is commonly used pattern, in fact I am using such
code quite a lot in our web-applications. I see two possibilities to
make this easier:
1. Introduce a method in MAContainer doing exactly what we saw above:
(anOrder description
flatten: (MASelectorAccessor selector: #billingAddress))
flatten: (MASelectorAccessor selector: #shippingAddress)
...
2. Introduce a special description doing the same:
Order>>descriptionBillingAddress
^ (MAComposedDescription selector: #billingAddress)
reference: Address description;
yourself.
Order>>descriptionShippingAddress
^ (MAComposedDescription selector: #shippingAddress)
reference: Address description;
yourself.
The first approach can lead to _duplicated_ code and tends to _waste_
memory. The problem with the second approach is that you have those
referenced objects _always_ in the description of Order, maybe you
don't want this. Probably we need both?
Any thoughts?
Lukas
--
Lukas Renggli
http://www.lukas-renggli.ch