PageContext and PageManager JavaScript classes

Client-side JavaScript Calipso programming heavy relies in two classes:
  • Comkarl,Web.PageContext. It's a class whose goal is holding PageManager for the page (explained in the next point in this list) and some utility methods:
    • HtmlDecode(String): It decodes a string containing HTML entities like í, ©...
    • GetQueryStringParameter(String). It gets a QueryString parameter by its name. For example, having an URL like http://blah.com/q=1, using this method you could retrevie "1" if you call Comkarl.Web.PageContext.GetQueryStringParameter("q").
    • get_PageManager(). It gets current PageManager instance.
  • Comkarl.Web.PageManager. It's a very important class as it manages client-side controls' life-cycle and exposes events that can be useful to do a lot of things. This is a summary of its members:
    • Events:
      • Init. This occurs when Page is going to be initialized, just before controls' collection initialization.
      • ControlInit. This occurs when some control is being initialized.
      • ControlReady. This occurs when Control gets ready-state
      • Loaded. This occurs when current Page has been completely loaded, just after acquiring ready-state.
      • Ready. This occurs when current Page has been completely rendered.

This is the order the order on which above events get raised:
  1. Init. PageManager raises this event so listeners can initialize resources prior to rendering.
  2. Ready. PageManager raises this event in order to tell listeners than can start rendering things, for example, controls.
  3. ControlInit. PageManager raises this event in order to tell listeners that a control is being initialized.
  4. ControlReady. PageManager raises this event in order to tell listeners that a control is ready (it has been rendered an initialized).
  5. Loaded. PageManager raises this event in order to tell listeners that all resources handled by itself have been already loaded.

In order to add a listener, you need to get an instance of PageManager from the PageContext:
Comkarl,Web.PageContext.get_Manager()


Event handlers are added using PageManager AddEventNameListener(...) methods. Handling some events may require functions accepting specific arguments:

Init event

It requires a parameterless function:
Comkarl,Web.PageContext.get_Manager().AddInitListener(
    function() {
           // Do sfuff
    }
);

Ready event

It requires a function that recieves a single argument pageManager which is an instance of the PageManager that raised the event:
Comkarl,Web.PageContext.get_Manager().AddReadyListener(
    function(pageManager) {
           // Do sfuff
    }
);

ControlInit event

It requires a function that recieves a single argument control which is an instance of the control that's being initialized:
Comkarl,Web.PageContext.get_Manager().AddControlInitListener(
    function(control) {
           // Do sfuff
    }
);

ControlReady event

It requires a function that recieves a single argument control which is an instance of the control that acquired ready state:
Comkarl,Web.PageContext.get_Manager().AddControlReadyListener(
    function(control) {
           // Do sfuff
    }
);

Loaded event

It requires a function that recieves a single argument pageManager which is an instance of the PageManager that raised the event:
Comkarl,Web.PageContext.get_Manager().AddLoadedListener(
    function(pageManager) {
           // Do sfuff
    }
);



Last edited Jul 25, 2012 at 1:09 PM by MFidemraizer, version 9

Comments

No comments yet.