[Glass] Problem assigning to temp vars from Seaside callbacks?

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

[Glass] Problem assigning to temp vars from Seaside callbacks?

Mariano Martinez Peck
Hi guys,

I am starting to see strange problems that happen only in GemStone but work correctly in Pharo.

I have a menu action that looks like this:


(aWebAppBrowser actionType new
context: #contextMenu;
argumentTypes:
{Object.
Collection.
(aWebAppBrowser class)};
label: 'SIXX Import and Replace DB';
block: [ :cls :collection :app | 
| list |
(app activeModelReport isKindOf: MAReport)
ifTrue: [ | filenameForm filename |
list := app objectsForActions. "filtered and sorted"
filenameForm := MyRenderedBlockFormDialog new.
filenameForm
buttonsAndCallbacksList: 
{(#import -> [ filenameForm answer: true ]).
(#cancel -> [ filenameForm answer: false ])};
renderingBlock: [ :html |
html text: 'Import filename prefix'.
html textInput
size: 100;
callback: [ :value | self halt. filename := value trimBoth ];
value: 'filename_here' ];
addForm.
(app call: filenameForm)
ifTrue: [
self halt.
]
]]


That action has the closure which is compiled once at the beginning of the app and then valued whenever clicked. Now...that closure creates an instance of MyRenderedBlockFormDialog which has a simple input for a filename. When I click on "import" the callback of the text input is invoked correctly. Soo....'filename' temp receives the value correctly. However, after the call to such a component (app call: filenameForm), (the "self halt" inside the ifTrue)... the temp var 'filename' has a nil!!!!   Any ideas why I get a nil here instead of the real value? 
Same code and same test in Pharo does work correctly.

Thanks in advance, 

--
Mariano
http://marianopeck.wordpress.com

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] Problem assigning to temp vars from Seaside callbacks?

Johan Brichau-3
Hey Mariano,

If you want to transfer values between callbacks (closures) in Seaside on Gemstone, you need to put the value in a valueholder object instead of assigning to method temporaries. Otherwise, you experience exactly what you see. That means, for example:

| valueholder|
valueholder := ValueHolder new.

html jQuery ajax
        callback: [:v | valueholder value: v];
        script: [:s | self doSomethingWith: valueholder value]

You can use anything you like as a valueholder: Association, Array, Set, ... whatever. As long as you are not directly assigning to the temporary var.
There is also code demonstrating this in the JQueryUI Autocomplete code of Seaside (gemstone version) [2].

I referred to that issue in this mail [1] but it was a bit condensed I guess.

cheers
Johan

[1] http://forum.world.st/Glass-Basic-questions-regarding-GemBuilder-for-Smalltalk-GemTools-and-tODE-tp4711463p4711987.html
[2] https://github.com/glassdb/Seaside31/blob/gemstone3.1/repository/JQuery-UI.package/JQAutocomplete.class/instance/search.labels.callback..st

On 27 Jan 2014, at 22:10, Mariano Martinez Peck <[hidden email]> wrote:

> Hi guys,
>
> I am starting to see strange problems that happen only in GemStone but work correctly in Pharo.
>
> I have a menu action that looks like this:
>
>
> (aWebAppBrowser actionType new
> context: #contextMenu;
> argumentTypes:
> {Object.
> Collection.
> (aWebAppBrowser class)};
> label: 'SIXX Import and Replace DB';
> block: [ :cls :collection :app |
> | list |
> (app activeModelReport isKindOf: MAReport)
> ifTrue: [ | filenameForm filename |
> list := app objectsForActions. "filtered and sorted"
> filenameForm := MyRenderedBlockFormDialog new.
> filenameForm
> buttonsAndCallbacksList:
> {(#import -> [ filenameForm answer: true ]).
> (#cancel -> [ filenameForm answer: false ])};
> renderingBlock: [ :html |
> html text: 'Import filename prefix'.
> html textInput
> size: 100;
> callback: [ :value | self halt. filename := value trimBoth ];
> value: 'filename_here' ];
> addForm.
> (app call: filenameForm)
> ifTrue: [
> self halt.
>
> ]
> ]]
>
>
> That action has the closure which is compiled once at the beginning of the app and then valued whenever clicked. Now...that closure creates an instance of MyRenderedBlockFormDialog which has a simple input for a filename. When I click on "import" the callback of the text input is invoked correctly. Soo....'filename' temp receives the value correctly. However, after the call to such a component (app call: filenameForm), (the "self halt" inside the ifTrue)... the temp var 'filename' has a nil!!!!   Any ideas why I get a nil here instead of the real value?
> Same code and same test in Pharo does work correctly.
>
> Thanks in advance,
>
> --
> Mariano
> http://marianopeck.wordpress.com
> _______________________________________________
> Glass mailing list
> [hidden email]
> http://lists.gemtalksystems.com/mailman/listinfo/glass

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] Problem assigning to temp vars from Seaside callbacks?

Mariano Martinez Peck



On Tue, Jan 28, 2014 at 5:36 AM, Johan Brichau <[hidden email]> wrote:
Hey Mariano,

If you want to transfer values between callbacks (closures) in Seaside on Gemstone, you need to put the value in a valueholder object instead of assigning to method temporaries. Otherwise, you experience exactly what you see. That means, for example:

| valueholder|
valueholder := ValueHolder new.

html jQuery ajax
        callback: [:v | valueholder value: v];
        script: [:s | self doSomethingWith: valueholder value]

You can use anything you like as a valueholder: Association, Array, Set, ... whatever. As long as you are not directly assigning to the temporary var.
There is also code demonstrating this in the JQueryUI Autocomplete code of Seaside (gemstone version) [2].

I referred to that issue in this mail [1] but it was a bit condensed I guess.


Thanks Johan!!!! That was exactly the problem and using a ValueHolder solved the problem. 
I didn't remember directly you comment in [1] but somewhere deep in my brain was it because I knew it was related to callbacks and temps ;)

BTW..... do you know if there is a slime rule or something to check this? I am sure I have many other places like this...

 
cheers
Johan

[1] http://forum.world.st/Glass-Basic-questions-regarding-GemBuilder-for-Smalltalk-GemTools-and-tODE-tp4711463p4711987.html
[2] https://github.com/glassdb/Seaside31/blob/gemstone3.1/repository/JQuery-UI.package/JQAutocomplete.class/instance/search.labels.callback..st

On 27 Jan 2014, at 22:10, Mariano Martinez Peck <[hidden email]> wrote:

> Hi guys,
>
> I am starting to see strange problems that happen only in GemStone but work correctly in Pharo.
>
> I have a menu action that looks like this:
>
>
> (aWebAppBrowser actionType new
>               context: #contextMenu;
>               argumentTypes:
>                               {Object.
>                                       Collection.
>                                       (aWebAppBrowser class)};
>               label: 'SIXX Import and Replace DB';
>               block: [ :cls :collection :app |
>                                       | list |
>                                       (app activeModelReport isKindOf: MAReport)
>                                               ifTrue: [ | filenameForm filename |
>                                                       list := app objectsForActions.  "filtered and sorted"
>                                                       filenameForm := MyRenderedBlockFormDialog new.
>                                                       filenameForm
>                                                               buttonsAndCallbacksList:
>                                                                       {(#import -> [ filenameForm answer: true ]).
>                                                                       (#cancel -> [ filenameForm answer: false ])};
>                                                               renderingBlock: [ :html |
>                                                                       html text: 'Import filename prefix'.
>                                                                       html textInput
>                                                                               size: 100;
>                                                                               callback: [ :value | self halt. filename := value trimBoth ];
>                                                                               value: 'filename_here' ];
>                                                               addForm.
>                                                       (app call: filenameForm)
>                                                               ifTrue: [
>                                                                       self halt.
>
>                                                               ]
>                                                       ]]
>
>
> That action has the closure which is compiled once at the beginning of the app and then valued whenever clicked. Now...that closure creates an instance of MyRenderedBlockFormDialog which has a simple input for a filename. When I click on "import" the callback of the text input is invoked correctly. Soo....'filename' temp receives the value correctly. However, after the call to such a component (app call: filenameForm), (the "self halt" inside the ifTrue)... the temp var 'filename' has a nil!!!!   Any ideas why I get a nil here instead of the real value?
> Same code and same test in Pharo does work correctly.
>
> Thanks in advance,
>
> --
> Mariano
> http://marianopeck.wordpress.com
> _______________________________________________
> Glass mailing list
> [hidden email]
> http://lists.gemtalksystems.com/mailman/listinfo/glass




--
Mariano
http://marianopeck.wordpress.com

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] Problem assigning to temp vars from Seaside callbacks?

Johan Brichau-3
On 28 Jan 2014, at 16:26, Mariano Martinez Peck <[hidden email]> wrote:

> BTW..... do you know if there is a slime rule or something to check this? I am sure I have many other places like this...

I remember to have tried that once, but I did not have too much understanding of writing Slime rules.
Actually, I'm still not reasonably good Slime rule writer. I wrote 1 rule for Seaside and got help from Lukas for that ;-)

So, no there is no rule for that.
Maybe it's feasible: you need to find assignments to method temporaries from within seaside callback blocks.

Johan
_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass