[Seaside] generating callback from ajax
johan at inceptive.be
Sun Sep 18 14:04:26 UTC 2011
I think there are more convenient ways to achieve this, but it indeed seems to be difficult to add a callback in a text/json callback. I have to withdraw my statement:
> In all kinds of callbacks, you can therefore access the callbacks dictionary without needing to 'reuse' an old canvas / rendercontext.
It seems that a text/json callback does not give you a render context. Either there is another way to get to the callbacks (I would have to look), or it seems there is a shortcoming here because you might want to register new callbacks (or generate action urls) inside text/json callbacks as well.
So I understand why you are reusing the canvas.
In any case, I think registering a callback when you have the renderContext available is more convenient when you use the jQuery wrappers.
For example, the following expression registers a callback and returns the url so you can pass it on to JQGrid.
dataUrl := (html jQuery ajax callback:[self ajaxCallback]) fullUrl
However, when you want to return json, the following is probably more appropriate:
dataUrl := (html jQuery getJson text:[:stream | ... ]) fullUrl
And, the real problem, as opposed to the #html: , #script:, and #load: callbacks, the #text: callback does not provide a renderContext.
imho, it might be easier to use a single callback and a different request parameter for each row. In that case, you even do not need to register callbacks.
Another option is to create a #text: callback that passes the rendercontext (similar to how #script: & #html: are implemented).
Let me think about this a bit more… it's an interesting problem.
On 17 Sep 2011, at 19:23, Milan Mimica wrote:
> On 17 September 2011 18:13, Johan Brichau <johan at inceptive.be> wrote:
>> How are you registering the callback that will that call the #ajaxCallback method?
>> I'm asking because I see no reason to have such a construction. If you are registering an ajax callback that is supposed to render something (html, script, json, …) Seaside provides you with an appropriate renderContext. In all kinds of callbacks, you can therefore access the callbacks dictionary without needing to 'reuse' an old canvas / rendercontext.
> I'm registering like this:
> rendererContext := html.
> dataUrl := rendererContext actionUrl copy
> addField: (rendererContext callbacks
> store: (JSAjaxCallback on: [ self ajaxCallback ]));
> And then inside ajaxCallback I want to register another callback and
> respond the url of it :)
> Why am I doing this? Well, trying to make best of jqGrid.
> I want a separate callback for each row, when edited. I am storing the
> callback url with the row data, in a hidden column, so the client
> knows where to report edits for each row. jqGrid obtains rows using a
> AJAX request. Hence I need to register a callback for each row
> returned to jqGrid in that AJAX request.
> I could register a callback for each row in advance, but there is a
> lot of rows and jqGrid does pagination... so that's not the way to go.
> Hm... maybe I could preregister a few dozen of callbacks when
> rendering and then in the callback just assign them to rows... could
> work, but it's ugly.
> Milan Mimica
> seaside mailing list
> seaside at lists.squeakfoundation.org
More information about the seaside