Glorp-Seaside-callback not Working

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Glorp-Seaside-callback not Working

Rajeev Lochan
Dear Seasiders,
I followed Ramon's Blog of porting seaside to postgreSQL using Glorp.
I have now created 2 components. In one, you can enter the details of the form (which are in the form of textInput and textArea) and are registered upon submitting a button. This part works well.

Now, in the second component, I want to edit(update) the entries I have created earlier. I use textInput and textArea again for this, and when I edit and submit using a button (register the model) , the update doesnt seem to work.

I have observed one thing here, the update doesnt seem to work in textInput value: callback:

A snippet is code is here.(which doesnt update the title)


self session
        commit: [temp := self session
                        readOneOf: BlogPost
                        where: [:each | each title = '1'].
                       html textInput value: temp title;
                        callback: [:value | temp title: value].
                         self session register: temp]



A snippet which uses simple setter technique and is updated.

self session
        commit: [temp := self session
                        readOneOf: BlogPost
                        where: [:each | each title = '1'].
                        temp title: 'some Title'.
                        self session register: temp].



Anticipating your help      




--
Rajeev Lochan

Co-founder, AR-CAD.com

http://www.ar-cad.com
+91 9243468076 (Bangalore)
080 65355873
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: Glorp-Seaside-callback not Working

Ron Teitelbaum

Hi Rajeev,

 

You need to register the object before you make changes to it.  The registration tells Glorp to track changes to your object.

 

Hope that helps!

Ron Teitelbaum

 


From: [hidden email] [mailto:[hidden email]] On Behalf Of Rajeev Lochan
Sent: Sunday, August 12, 2007 11:52 AM
To: Seaside - general discussion
Subject: [Seaside] Glorp-Seaside-callback not Working

 

Dear Seasiders,
I followed Ramon's Blog of porting seaside to postgreSQL using Glorp.
I have now created 2 components. In one, you can enter the details of the form (which are in the form of textInput and textArea) and are registered upon submitting a button. This part works well.

Now, in the second component, I want to edit(update) the entries I have created earlier. I use textInput and textArea again for this, and when I edit and submit using a button (register the model) , the update doesnt seem to work.

I have observed one thing here, the update doesnt seem to work in textInput value: callback:

A snippet is code is here.(which doesnt update the title)


self session
        commit: [temp := self session
                        readOneOf: BlogPost
                        where: [:each | each title = '1'].
                       html textInput value: temp title;
                        callback: [:value | temp title: value].
                         self session register: temp]



A snippet which uses simple setter technique and is updated.

self session
        commit: [temp := self session
                        readOneOf: BlogPost
                        where: [:each | each title = '1'].
                        temp title: 'some Title'.
                        self session register: temp].



Anticipating your help      




--
Rajeev Lochan

Co-founder, AR-CAD.com

http://www.ar-cad.com
+91 9243468076 (Bangalore)
080 65355873


_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Glorp-Seaside-callback not Working

Rajeev Lochan
Hi Ron,
I tried to implement what you hinted, no progress.

I changed my code to

html
        form: [self session
                commit: [temp := self session
                                readOneOf: BlogPost
                                where: [:each | each persistentId = '1'].
                    self session register: temp.
                    html textInput value: temp title;
                       
                        callback: [:value | temp title: value].
                    html submitButton
                        callback: [self session register: temp];
                         text: 'Update']]


I am registering before change as you said, but doesnt change the title. (I am registering twice though)


But, even if I dont register the object, before changing. It does update if I use normal setter technique. (Snippet below)

html
        form: [self session
                commit: [temp := self session
                                readOneOf: BlogPost
                                where: [:each | each persistentId = '1'].
                    temp title: 'some Title'.
                    html submitButton
                        callback: [self session register: temp];
                         text: 'Update']]




In Glorp Tutorial by Roger Whitney, he updated in just unitOfWork and also without registering it.

"   A UnitOfWork will keep track of the changes we make in objects. The following will retrieve a
person, change the first name of person and then write the changes back to the database.

session beginUnitOfWork.
foundPerson := session readOneOf: Person where: [:each | each firstName = 'Jose'].
foundPerson firstName: 'RamJet'.
session commitUnitOfWork

When we start a UnitOfWork it records all the objects we read from the database. When the
UnitOfWork is committed it writes all the changed objects back to the database."


As much I understand, it has something to do with
self session commit:[ ........... html textInput value: callback: ...........]


BTW, I am not using Magritte in my proposed application. So Ramon's Active Record for Magritte would possibly not help me much.

Thanks in advance.


On 8/12/07, Ron Teitelbaum <[hidden email]> wrote:

Hi Rajeev,

 

You need to register the object before you make changes to it.  The registration tells Glorp to track changes to your object.

 

Hope that helps!

Ron Teitelbaum

 


From: [hidden email] [mailto:[hidden email]] On Behalf Of Rajeev Lochan
Sent: Sunday, August 12, 2007 11:52 AM
To: Seaside - general discussion
Subject: [Seaside] Glorp-Seaside-callback not Working

 

Dear Seasiders,
I followed Ramon's Blog of porting seaside to postgreSQL using Glorp.
I have now created 2 components. In one, you can enter the details of the form (which are in the form of textInput and textArea) and are registered upon submitting a button. This part works well.

Now, in the second component, I want to edit(update) the entries I have created earlier. I use textInput and textArea again for this, and when I edit and submit using a button (register the model) , the update doesnt seem to work.

I have observed one thing here, the update doesnt seem to work in textInput value: callback:

A snippet is code is here.(which doesnt update the title)


self session
        commit: [temp := self session
                        readOneOf: BlogPost
                        where: [:each | each title = '1'].
                       html textInput value: temp title;
                        callback: [:value | temp title: value].
                         self session register: temp]



A snippet which uses simple setter technique and is updated.

self session
        commit: [temp := self session
                        readOneOf: BlogPost
                        where: [:each | each title = '1'].
                        temp title: 'some Title'.
                        self session register: temp].



Anticipating your help      




--
Rajeev Lochan

Co-founder, AR-CAD.com

<a href="http://www.ar-cad.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.ar-cad.com
+91 9243468076 (Bangalore)
080 65355873


_______________________________________________
Seaside mailing list
[hidden email]
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank">http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside




--
Rajeev Lochan

Co-founder, AR-CAD.com

http://www.ar-cad.com
+91 9243468076 (Bangalore)
080 65355873
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: Glorp-Seaside-callback not Working

Ron Teitelbaum
Hi Rajeev,

I’m having some trouble understanding.

What I would suggest is that you separate your db code from your
presentation code.  

Create a BlogItem before calling the form, or as the result of some action
on the form and hold that item in an ivar.  You could either register the
object when you read it or reapply the changes as a result of committing the
object.

Also notice that self session on a subclass of WAComponent normally returns
a Seaside Session and not a glorp session.  Unless you extended your seaside
session to hold onto to your glorp session, that could be causing your
problem.  

You should consider calling beginTransaction and commitTransaction or
rollbackTransaction yourself instead of using inTransactionDo: or commit:
wrapping your presentation code can be done but it's not pretty.

Ok so this is not what I did, but what I did was much more complicated.
What I did was extend the error handling of Seaside so that I could add a
dirtySet on each application (I extended the seaside session).  Then I
signal an error for every newly created object and db read.  The application
checks all the nested applications and components to see which component
wants to handle commits, and it adds the object to the commit dirtySet.
Then when someone hits commit I do the change management myself, and commit
things at that time (register, apply changes, commit).  This allows me to
handle multiple types of commits (not everything goes through glorp).  It's
a lot more complicated but it works well.

Anyway if you separate your presentation and db code things should make more
sense.  The form should only display and change the blogItem in its ivar.
When you commit or cancel it should perform some commitObjects code or
rollback code.  The Glorp code should not be in the form itself.

So before calling your component read your BlogItem, start a transaction on
your glorp session, register your object, then call your form.  Let the form
make changes to the object and either commit or cancel.  Commit should just
call self glorpSession commitTransaction, etc.  

Hope that helps!
Ron Teitelbaum
________________________________________
From: Rajeev Lochan [mailto:[hidden email]]
Sent: Sunday, August 12, 2007 12:53 PM
To: [hidden email]; Seaside - general discussion
Subject: Re: [Seaside] Glorp-Seaside-callback not Working

Hi Ron,
I tried to implement what you hinted, no progress.

I changed my code to

html
        form: [self session
                commit: [temp := self session
                                readOneOf: BlogPost
                                where: [:each | each persistentId = '1'].
                    self session register: temp.
                    html textInput value: temp title;
                       
                        callback: [:value | temp title: value].
                    html submitButton
                        callback: [self session register: temp];
                         text: 'Update']]


I am registering before change as you said, but doesnt change the title. (I
am registering twice though)


But, even if I dont register the object, before changing. It does update if
I use normal setter technique. (Snippet below)

html
        form: [self session
                commit: [temp := self session
                                readOneOf: BlogPost
                                where: [:each | each persistentId = '1'].
                    temp title: 'some Title'.
                    html submitButton
                        callback: [self session register: temp];
                         text: 'Update']]




In Glorp Tutorial by Roger Whitney, he updated in just unitOfWork and also
without registering it.

"   A UnitOfWork will keep track of the changes we make in objects. The
following will retrieve a
person, change the first name of person and then write the changes back to
the database.

session beginUnitOfWork.
foundPerson := session readOneOf: Person where: [:each | each firstName =
'Jose'].
foundPerson firstName: 'RamJet'.
session commitUnitOfWork

When we start a UnitOfWork it records all the objects we read from the
database. When the
UnitOfWork is committed it writes all the changed objects back to the
database."


As much I understand, it has something to do with
self session commit:[ ........... html textInput value: callback:
...........]


BTW, I am not using Magritte in my proposed application. So Ramon's Active
Record for Magritte would possibly not help me much.

Thanks in advance.

On 8/12/07, Ron Teitelbaum <[hidden email]> wrote:
Hi Rajeev,
 
You need to register the object before you make changes to it.  The
registration tells Glorp to track changes to your object.
 
Hope that helps!
Ron Teitelbaum
 
________________________________________
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Rajeev
Lochan
Sent: Sunday, August 12, 2007 11:52 AM
To: Seaside - general discussion
Subject: [Seaside] Glorp-Seaside-callback not Working
 
Dear Seasiders,
I followed Ramon's Blog of porting seaside to postgreSQL using Glorp.
I have now created 2 components. In one, you can enter the details of the
form (which are in the form of textInput and textArea) and are registered
upon submitting a button. This part works well.

Now, in the second component, I want to edit(update) the entries I have
created earlier. I use textInput and textArea again for this, and when I
edit and submit using a button (register the model) , the update doesnt seem
to work.

I have observed one thing here, the update doesnt seem to work in textInput
value: callback:

A snippet is code is here.(which doesnt update the title)


self session
        commit: [temp := self session
                        readOneOf: BlogPost
                        where: [:each | each title = '1'].
                       html textInput value: temp title;
                        callback: [:value | temp title: value].
                         self session register: temp]



A snippet which uses simple setter technique and is updated.

self session
        commit: [temp := self session
                        readOneOf: BlogPost
                        where: [:each | each title = '1'].
                        temp title: 'some Title'.
                        self session register: temp].



Anticipating your help      




--
Rajeev Lochan

Co-founder, AR-CAD.com

http://www.ar-cad.com
+91 9243468076 (Bangalore)
080 65355873

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside 



--
Rajeev Lochan

Co-founder, AR-CAD.com

http://www.ar-cad.com
+91 9243468076 (Bangalore)
080 65355873

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Glorp-Seaside-callback not Working

Alan Knight-2
In reply to this post by Rajeev Lochan
In general, if you have a unit of work in progress, then any objects you read during that unit of work will be registered automatically. Registering more than once should do no harm, as long as the object was registered before it was modified.

I don't know why you would be having that particular problem, but I don't know exactly what the methods commit: and and the callback does. It would depend on the flow of control. If seaside is blocking, then the unit of work won't have committed, so I would expect the changes to be seen. However, if Seaside lets your process keep going when you register the callback, then presumably it will have already fallen through, and committed the unit of work before any changes were made.

So you'd need to either be using Seaside API's that "block" the calling process. Or you'd need to begin the unit of work here, and commit it explicitly later. So, for example, I think it might work if you put the call to commit the unit of work in the callback for the submit button. Although you might have to do some fiddling in case it gets called more than once due to continuations or other mechanisms.

At 12:53 PM 8/12/2007, Rajeev Lochan wrote:
Hi Ron,
I tried to implement what you hinted, no progress.

I changed my code to

html
        form: [self session
                commit: [temp := self session
                                readOneOf: BlogPost
                                where: [:each | each persistentId = '1'].
                    self session register: temp.
                    html textInput value: temp title;
                       
                        callback: [:value | temp title: value].
                    html submitButton
                        callback: [self session register: temp];
                         text: 'Update']]


I am registering before change as you said, but doesnt change the title. (I am registering twice though)


But, even if I dont register the object, before changing. It does update if I use normal setter technique. (Snippet below)

html
        form: [self session
                commit: [temp := self session
                                readOneOf: BlogPost
                                where: [:each | each persistentId = '1'].
                    temp title: 'some Title'.
                    html submitButton
                        callback: [self session register: temp];
                         text: 'Update']]




In Glorp Tutorial by Roger Whitney, he updated in just unitOfWork and also without registering it.

"   A UnitOfWork will keep track of the changes we make in objects. The following will retrieve a
person, change the first name of person and then write the changes back to the database.

session beginUnitOfWork.
foundPerson := session readOneOf: Person where: [:each | each firstName = 'Jose'].
foundPerson firstName: 'RamJet'.
session commitUnitOfWork

When we start a UnitOfWork it records all the objects we read from the database. When the
UnitOfWork is committed it writes all the changed objects back to the database."


As much I understand, it has something to do with
self session commit:[ ........... html textInput value: callback: ...........]


BTW, I am not using Magritte in my proposed application. So Ramon's Active Record for Magritte would possibly not help me much.

Thanks in advance.


On 8/12/07, Ron Teitelbaum <[hidden email]
> wrote:

Hi Rajeev,

 

You need to register the object before you make changes to it.  The registration tells Glorp to track changes to your object.

 

Hope that helps!

Ron Teitelbaum

 

From: [hidden email] [[hidden email]] On Behalf Of Rajeev Lochan
Sent: Sunday, August 12, 2007 11:52 AM
To: Seaside - general discussion
Subject: [Seaside] Glorp-Seaside-callback not Working

 

Dear Seasiders,
I followed Ramon's Blog of porting seaside to postgreSQL using Glorp.
I have now created 2 components. In one, you can enter the details of the form (which are in the form of textInput and textArea) and are registered upon submitting a button. This part works well.

Now, in the second component, I want to edit(update) the entries I have created earlier. I use textInput and textArea again for this, and when I edit and submit using a button (register the model) , the update doesnt seem to work.

I have observed one thing here, the update doesnt seem to work in textInput value: callback:

A snippet is code is here.(which doesnt update the title)


self session
        commit: [temp := self session
                        readOneOf: BlogPost
                        where: [:each | each title = '1'].
                       html textInput value: temp title;
                        callback: [:value | temp title: value].
                         self session register: temp]



A snippet which uses simple setter technique and is updated.

self session
        commit: [temp := self session
                        readOneOf: BlogPost
                        where: [:each | each title = '1'].
                        temp title: 'some Title'.
                        self session register: temp].



Anticipating your help      




--
Rajeev Lochan

Co-founder, AR-CAD.com

http://www.ar-cad.com
+91 9243468076 (Bangalore)
080 65355873

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside




--
Rajeev Lochan

Co-founder, AR-CAD.com

http://www.ar-cad.com
+91 9243468076 (Bangalore)
080 65355873
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

--
Alan Knight [|], Cincom Smalltalk Development

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Glorp-Seaside-callback not Working

Rajeev Lochan
In reply to this post by Rajeev Lochan
Thanks Ron and Alan, I shall try to implement what you have suggested and comeback to you when done( commit) or having problems again(Rollback)  ;-)



On 8/13/07, Alan Knight <[hidden email]> wrote:
In general, if you have a unit of work in progress, then any objects you read during that unit of work will be registered automatically. Registering more than once should do no harm, as long as the object was registered before it was modified.

I don't know why you would be having that particular problem, but I don't know exactly what the methods commit: and and the callback does. It would depend on the flow of control. If seaside is blocking, then the unit of work won't have committed, so I would expect the changes to be seen. However, if Seaside lets your process keep going when you register the callback, then presumably it will have already fallen through, and committed the unit of work before any changes were made.

So you'd need to either be using Seaside API's that "block" the calling process. Or you'd need to begin the unit of work here, and commit it explicitly later. So, for example, I think it might work if you put the call to commit the unit of work in the callback for the submit button. Although you might have to do some fiddling in case it gets called more than once due to continuations or other mechanisms.


At 12:53 PM 8/12/2007, Rajeev Lochan wrote:
Hi Ron,
I tried to implement what you hinted, no progress.

I changed my code to

html
        form: [self session
                commit: [temp := self session
                                readOneOf: BlogPost
                                where: [:each | each persistentId = '1'].
                    self session register: temp.
                    html textInput value: temp title;
                       
                        callback: [:value | temp title: value].
                    html submitButton
                        callback: [self session register: temp];
                         text: 'Update']]


I am registering before change as you said, but doesnt change the title. (I am registering twice though)


But, even if I dont register the object, before changing. It does update if I use normal setter technique. (Snippet below)

html
        form: [self session
                commit: [temp := self session
                                readOneOf: BlogPost
                                where: [:each | each persistentId = '1'].
                    temp title: 'some Title'.
                    html submitButton
                        callback: [self session register: temp];
                         text: 'Update']]




In Glorp Tutorial by Roger Whitney, he updated in just unitOfWork and also without registering it.

"   A UnitOfWork will keep track of the changes we make in objects. The following will retrieve a
person, change the first name of person and then write the changes back to the database.

session beginUnitOfWork.
foundPerson := session readOneOf: Person where: [:each | each firstName = 'Jose'].
foundPerson firstName: 'RamJet'.
session commitUnitOfWork

When we start a UnitOfWork it records all the objects we read from the database. When the
UnitOfWork is committed it writes all the changed objects back to the database."


As much I understand, it has something to do with
self session commit:[ ........... html textInput value: callback: ...........]


BTW, I am not using Magritte in my proposed application. So Ramon's Active Record for Magritte would possibly not help me much.

Thanks in advance.


On 8/12/07, Ron Teitelbaum <[hidden email]
> wrote:

Hi Rajeev,

 

You need to register the object before you make changes to it.  The registration tells Glorp to track changes to your object.

 

Hope that helps!

Ron Teitelbaum

 

From: [hidden email] [[hidden email]] On Behalf Of Rajeev Lochan
Sent: Sunday, August 12, 2007 11:52 AM
To: Seaside - general discussion
Subject: [Seaside] Glorp-Seaside-callback not Working

 

Dear Seasiders,
I followed Ramon's Blog of porting seaside to postgreSQL using Glorp.
I have now created 2 components. In one, you can enter the details of the form (which are in the form of textInput and textArea) and are registered upon submitting a button. This part works well.

Now, in the second component, I want to edit(update) the entries I have created earlier. I use textInput and textArea again for this, and when I edit and submit using a button (register the model) , the update doesnt seem to work.

I have observed one thing here, the update doesnt seem to work in textInput value: callback:

A snippet is code is here.(which doesnt update the title)


self session
        commit: [temp := self session
                        readOneOf: BlogPost
                        where: [:each | each title = '1'].
                       html textInput value: temp title;
                        callback: [:value | temp title: value].
                         self session register: temp]



A snippet which uses simple setter technique and is updated.

self session
        commit: [temp := self session
                        readOneOf: BlogPost
                        where: [:each | each title = '1'].
                        temp title: 'some Title'.
                        self session register: temp].



Anticipating your help      




--
Rajeev Lochan

Co-founder, AR-CAD.com

<a href="http://www.ar-cad.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.ar-cad.com
+91 9243468076 (Bangalore)
080 65355873

_______________________________________________
Seaside mailing list
[hidden email]
<a href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside <a href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">




--
Rajeev Lochan

Co-founder, AR-CAD.com

<a href="http://www.ar-cad.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.ar-cad.com
+91 9243468076 (Bangalore)
080 65355873
_______________________________________________
Seaside mailing list
[hidden email]
<a href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
--
Alan Knight [|], Cincom Smalltalk Development
<a href="http://www.cincom.com/smalltalk" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://www.cincom.com/smalltalk

_______________________________________________
Seaside mailing list
[hidden email]
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank">http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside




--
Rajeev Lochan

Co-founder, AR-CAD.com

http://www.ar-cad.com
+91 9243468076 (Bangalore)
080 65355873
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside