Thanks for the response. Sorry I was so long in getting back to this.
December is a pretty insane month for me at the moment. :) (comments
below)
On Nov 29, 2007 8:00 AM, Lukas Renggli <renggli(a)iam.unibe.ch> wrote:
This is where I need the custom memento (and tell
me if I'm doing this
wrong): If you click save that winds up calling "commit" on the
memento and actually writing the data to the object, but this new
object wont be registered in the class side collection (and therefor
will simply cease to exist when this session expires). So my custom
memento simply lets everything work as normal and then calls "Person
register: self model" to get the new object registered.
Sure that's a possibility, but why not use the return value if you are
using #call: or set an #onAnswer: handler if you are using composition?
Well, the thing is, I'm using a shortcut here. :) The manager just
basically provides a web page that allows one to use the descriptions
of other two. It doesn't use call because it doesn't want anything
back. Maybe an example will make it clearer.
Manager>>renderContentOn: html
html render: self component
>component
^ component ifNil: [
component := ((self housesComponent, self peopleComponent)
asComponentOn: self)
addForm: #(); "I don't want any buttons on this form since
submitting it would make no sense, I do nothing with the values here"
yourself ] "since the House and Person classes
manage their own instances"
>housesComponent "gives a nice view for
managing houses"
^ MAToManyRelationDescription new
classes: (Array with: House);
label: 'Houses';
accessor: (MASelectorAccessor new
readSelector: #houses;
writeSelector: nil;
yourself);
default: Array new;
priority: 20;
yourself
>peopleComponent "ditto for people"
^ MAToManyRelationDescription new
classes: (Array with: Person);
label: 'People';
accessor: (MASelectorAccessor new
readSelector: #people;
writeSelector: nil;
yourself);
default: Array new;
priority: 20;
yourself
>houses
^ House instances
>people
^ Person instances
So in your manager you have something along:
house := self call: House new asComponent.
house ifNotNil: [ House register: house ].
or (in case of composition):
editor := House new asComponent onAnswer: [ :house |
house ifNotNil: [ House register: house ].
editor := nil ]
This I tried. It doesn't work when I put it on #houseComponent or
#storeComponent since I'm using #, and when I put it in #component it
seems to be ignored.
The problem
happens when "save" returns on Person and you go back to
the manager page. You see your nice new Person in the report table as
expected, but right below is the same Person again! And if you edit
either one the changes reflect in both. And the really hairy thing
is, even though House is almost exactly the same in every way (I can
find no relevant difference) it doesn't have this behavior.
Looks like your memento method gets called twice? Why not check if the
object is already present? Why not use a Set then?
Ah but I do. Since I'm in the momento I have to check if there
already exists an object that has the same value as the ones cached in
the momento. I had a #break call in the momento and I'm sure it's not
getting called twice, which wouldn't hurt anything if it did. It
seems like the MA machinery is doing some caching of some kind. The
part that baffles me is that it doesn't happen for Houses, even though
they are fundamentally exactly the same.
I suppose this would be so much easier if I just let Magritte manage
everything completely, but this code gets managed in other places then
on these web pages.
Cheers,
Lukas
--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki