[Seaside] Executing form callbacks within a block

Esteban Maringolo emaringolo at gmail.com
Thu May 20 14:10:12 UTC 2021


Well..

I'm not writing the values directly to the database, but I'm using
GLORP in between.
Glorp detects changes and at the end of a "unit of work" (kinda
transaction) it creates the corresponding statements to
write/update/delete rows in the database. But in order to do that it
has to know the object "state" before starting doing mutations on it.

So what I finally did was to have a hidden input as the first callback.

A super simplified version, without validations and whatnot is like this:

html form: [
  html hiddenInput callback: [self db beginUnitOrWork. self db
register: self model].
  html textInput on: #name of: self model.
  html submitButton callback: [self db commitUnitOfWork]
]

Regards!

Esteban A. Maringolo

On Wed, May 19, 2021 at 10:59 PM Jupiter Jones <jupiter.jones at mail.com> wrote:
>
> To be clearer… :)
>
> No callback on the submit button.
>
> html form callback: [
>         self beginTransaction.
>         “Update database from #name and #age fields”
>         self commitTransaction
> ]
>
> > On 20 May 2021, at 11:55 am, Jupiter Jones <jupiter.jones at mail.com> wrote:
> >
> > It’s been a while since I’ve done this, but if you have a callback on the form itself, which handles validation and if valid, starts a transaction, moves the data from the temporary variables used by the web form to the database, then commits.
> >
> > I’m guessing from the question that you may have bound your inputs directly to database objects that will revert their value when you beginTransaction?
> >
> >> On 20 May 2021, at 11:18 am, Esteban Maringolo <emaringolo at gmail.com> wrote:
> >>
> >> Hi all,
> >>
> >> I have a situation where I want to execute _ALL_ the callbacks of the
> >> inputs in the form within a particular block (basically, a DB
> >> transaction).
> >>
> >> html form: [
> >> html textInput on: #name of: self.
> >> html textInput on: #age of: self.
> >> html submitButton
> >> ]
> >>
> >> I want to execute the three callbacks within something else, or at
> >> least have the option to execute something before the first callback
> >> executes and ensure something gets executed after the last one is
> >> executed.
> >>
> >> I know it involves fiddling somehow with
> >> WACallbackProcessingActionContinuation, but it's not fully clear if I
> >> could do this.
> >>
> >> The hacky alternative would be to have a hidden field that does start
> >> the tx and the submit / cancel commits or cancels it.
> >>
> >> html form: [
> >> html hiddenInput callback: [self beginTransaction].
> >> html textInput on: #name of: self.
> >> html textInput on: #age of: self.
> >> html submitButton
> >>   callback: [self commitTransaction];
> >>   value: 'Submit'.
> >> ]
> >>
> >> But in this case I'd have to keep the tx "outside" of the form, and
> >> I'd like to wrap everything in a single block.
> >>
> >> Is there a way to do this with Seaside?
> >>
> >> Thanks!
> >>
> >> Esteban A. Maringolo
> >> _______________________________________________
> >> seaside mailing list
> >> seaside at lists.squeakfoundation.org
> >> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
> >
>


More information about the seaside mailing list