[Cubicweb] StartupView and self._cw.add_onload method

Adrien Di Mascio adrien.dimascio at logilab.fr
Fri Sep 9 08:57:04 CEST 2011


Hi Carlos,

On 08/09/2011 15:47, Carlos Balderas wrote:
> I would like to use self._cw.add_onload() method in a StartupView but I
> am getting an error when I call this view by itself,  it is a javascript
> error about unloadPageDate(),

There is no specific care to take before calling ``add_onload()``. The 
``undefined function unloadPageData`` error is unrelated and is more 
probably caused by an element of your page either requiring a tabindex, 
a rql_varmaker. You shouldn't have to worry about that and this is most 
probably a bug in CW.

To make things a bit clearer, when you're generating a page on the 
server side, it gets associated a unique identifier. This identifier is 
accessible by the ``pageid`` variable on the client side. When there's a 
need to store session data specific to this page, 
``req.set_page_data()`` is called on the server side during page 
construction. Because this so called "page data" needs to be cleared 
when the page is destroyed to avoid memory leaks, the ``unloadPageData`` 
function is bound to the ``on-unload`` javascript event. This function 
is, as you said, defined in ``cubicweb.ajax.js`` and performs and ajax 
call to remove its corresponding data from the session data.

That said, ``set_page_data()`` doesn't automaticlally adds 
``cubicweb.ajax.js`` to the list of dependencies, this is probably the 
cause of your error case and that's a CW bug.

Regards,
-- 
Adrien Di Mascio - LOGILAB, Paris (France).
Tél: 01.45.32.03.12
Formations - http://www.logilab.fr/formations
Développements - http://www.logilab.fr/services
Gestion de connaissances - http://www.cubicweb.org/



More information about the Cubicweb mailing list