[Seaside] Dynamically adding children

Philippe Marschall philippe.marschall at gmail.com
Tue Oct 3 06:35:36 UTC 2006

2006/10/3, Francois Beausoleil <francois.beausoleil at gmail.com>:
> Hi all !
> I'm still learning my way around Smalltalk / Seaside.  I have the
> regular Address Book application running.  I have Name, Address, Phone
> and Contact model objects.  I have corresponding *Editor classes too.
> I can edit objects which already have addresses, and now I'm ready to
> tackle adding new addresses from the UI.
> A Contact has many Addresses, and Contact sports these methods to access them:
> #addresses
> #addressAt:
> #addressAt:put:
> What I want to achieve is on the contact editor form, I want a place
> where I can type the name/location of the new address, and after
> submitting the form, a new, blank, AddressEditor should be appended to
> the general form.
> Here is my incomplete solution:
> html form: [
>         html fieldsetWithLegend: 'Contact' do: [
>         html render: nameEditor.
>         html divNamed: 'addresses' with: [
>                 html label: 'New address named' input: [
>                 html textInputWithCallback: [:name |
>                         self model addressAt: name put: Address new.
>                         subcomponents add: (self addressEditorFor: (self model addressAt:
> name) named: name)].
>                 html submitButton.
>                 addressEditors keysAndValuesDo: [:location :editor |
>                         html divClass: 'address' with:  [html render: editor]]]].
>         html submitButtonWithAction: [self save]]]
> I don't even know if it's valid to change subcomponents (which is
> returned by #children) while callbacks are being processed.  I found a
> thread[1] which explained a similar problem, except the OP was doing
> it with live updates.  I'm not ready for that yet.
> Anyway, it's probably something simple, and I'm not finding it.  I
> must also be using the wrong query in GMail, because I can't find
> anything remotely resembling what I want.

Yes this is valid. Just make sure you backtrack the component you add
the childeren to. The simplest way to do this is add:

self session registerObjectForBacktracking: self

in the initialize method of the component.


More information about the Seaside mailing list