Child pages
  • New in 7.0

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Starting from Servoy 6 there is a new onRender event added to Forms, Portals and Elements. The aim of this event is to allow changing display properties of supporting components just before they are shown or updated.

On Form and Portals the event is fired not only for the Form/Portal itself, but also for all the elements the standard Servoy Elements on the Form/Portal, if the element does not have its own onRender event handler. The . The Form/Portal level onRedner event will not fire for beans.

The onRender event handler is called with a parameter of type JSRenderEvent, that provides the following functions:

  • getRecord(): the record of the rendered object
  • getRecordIndex(): the index of the rendered object
  • getRenderable(): the rendered object:
    The returned element object is of type Renderable and it has the
    properties that can be changed (bgcolor, border, enabled,
    fgcolor, font, toolTipText, transparent, visible) and also
    utility Renderable. A Renderable object can be an instance of a RuntimeForm, RuntimePortal or any of the other RuntimeXxxx elements. 
    The Renderable class exposes all the properties that can be set in the onRender event and also utility functions to get the rendering element type and its
    dataprovider.hasFocus() whether or not the rendered object has the focusits dataprovider.
    The Renderable class is a generic class and some of the properties and methods are not applicable on the actual object being rendered. For example, if the object being rendered is an instance of RuntimeForm, the property toolTipText or the method getDataProviderID are irrelevant. When these are set/called anyway, they will fail silently 
  • hasFocus(): whether or not the rendered object has the focus
  • isRecordSelected(): whether or not the record of the rendering object is selected

Here is a sample usage for alternative row coloring :

...

Any updates made in the onRender event to the rendering object are valid until the onRender event is called again on the same object: when the Renderable object goes into the onRender event the object is as it is defined in the SolutionModel. This means that changes made in the previous onRender cycle are not there anymore, but also any scripted changes to the element at Runtime are not there anymore.

Example use: Making negative values in a column red

Code Block

/**
 * Called before the form component is rendered.
 *
 * @param {JSRenderEvent} event the render event
 */
function onRender(event) {
 /** @type {
	if(event.getRenderable() instanceof RuntimeComponent) {
		JSRecord<db:/udm/orders>}*/
 var rec = event.getRecord()
 if (rec.amt_tax == 0) {
    event.getRenderable().bgcolorfgcolor = '#ff0000#ff6600';
 } 	else
		else if (rec.amt_tax < 0) {
    event.getRenderable().bgcolorfgcolor = '#00ff00#ff0000';
 }
}
rowBGColorCalculation replacement

Using onRender you can replace rowBGColorCalculation events as
you can change the display of row elements just before they are
displayed. This is why, rowBGColorCalculation has been deprecated in
Servoy 6

Tips

...

(warning)  About performance: The onRender event will be fired often., It's therefor advised to keep the logic inside the onRender event handler method as optimized as possible, for quick execution. It's advised to refrain from calling any code outside the API of the JSRenderEvent or the Renderable class.

Inheritance model

The Inheritance model of Servoy has been enhanced to allow:

...