[OpenLayers-Dev] Possible bug with Protocol.HTTP
Eric Lemoine
eric.lemoine at camptocamp.com
Tue May 4 04:05:46 EDT 2010
On Tue, May 4, 2010 at 5:16 AM, Stephen Woodbridge
<woodbri at swoodbridge.com> wrote:
> Hi Eric,
>
> First off, thank you for your responses and help with this issue. The
> most important part is that I have code working and doing what I want,
> but I had to modify Protocol.HTTP and my server code to get it working.
> Eventually I would like to get it to work without modified OL code, but
> other work is higher priority at the moment. Given that this was not
> trivial and I think there might be some bugs in the code, I am
> continuing this thread with the hope of a) learning something and/or b)
> giving something back to make the code better if I can.
>
>>
>> I think this is expected.
>>
>> For the "commit" operation multiple callbacks come into play. The
>> main callback, called when the full commit operation completes, is
>> set in the "callback" option. Sub-operation callbacks can also be
>> set.
>>
>> If you had one or more of these sub-operation callbacks set you'd see
>> them being called in callUserCallback when committing (i.e. calling
>> protocol.commit()).
>>
>> To set sub-operation callbacks you'd use something like the following
>> in the options:
>>
>>
>> "create": { "callback": function() { alert("create"); } }, "update":
>> { "callback": function() { alert("update"); } }, "delete": { "callback":
>> function() { alert("delete"); } }
>
> Right, this is my read on the code, BUT you can not do this when you
> initialize the Protocol.HTTP object, because these will over write the
> functions of the same name in the class,
hmm... right, this sounds like a problem, I'll look into it when I get a chance.
> you have to initialize the
> object then extend:
>
> OpenLayers.Protocol.HTTP.options
>
> in theory, but I could not get these to be invoked in my code either.
>
> Also, looking at the docs the sub-operation callbacks above might only
> be valid if passed in the options object to the commit method, but I
> have not re-read the code on this point.
You may be right. Do you think it's a problem that sub-operation
callbacks can be specified in the options to the commit method only?
> I fully admit that it is likely that I do not understand how to use the
> code correctly, but it is not from lack of trying and spending a bunch
> of time off and on this problem over the last month.
No no, you're getting it :-)
>
>>> A simple test of this is to create an OpenLayers.Protocol.HTTP with
>>> a
>>>
>>> callback: function() {alert( "Hello World!"); }
>>>
>>> and issue a create, update, or delete request via the protocol and
>>> the callback is not currently called.
>>
>> The callback function should get called here. I'd be interested in a
>> example showing this doesn't work.
>
> Here is a simple example based on the examples/sundials.html where I
> just added the callback to that and it is not called.
>
> http://imaptools.com:8080/ol29/examples/sundials2.html
>
> var sundials = new OpenLayers.Layer.Vector("KML", {
> projection: map.displayProjection,
> strategies: [new OpenLayers.Strategy.Fixed()],
> protocol: new OpenLayers.Protocol.HTTP({
> url: "kml/sundials.kml",
> format: new OpenLayers.Format.KML({
> extractStyles: true,
> extractAttributes: true
> }),
> callback: function(){ alert("Hello!"); } // <<<<<<<<
> })
> });
>
> Maybe this is a bad example and callback is not invoked on read requests
> which is the only request in this example, but there is not much
> documentation on how or when the callback is supposed to be used.
In this case your callback isn't called because of the Fixed strategy.
The strategy calls protocol.read and provides its own callback to the
read method, so this overrides the "global" callback. If your app code
does protocol.read() somewhere then your "global" callback func will
get invoked.
Cheers,
--
Eric Lemoine
Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex
Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com
More information about the Dev
mailing list