onRender infinite loop in tab with more than 1 record

Discuss all problems you have with Servoy here. It might help to mention the Servoy version and Operating System version you are using

onRender infinite loop in tab with more than 1 record

Postby rafig » Thu May 23, 2013 4:15 pm

Hi,
maybe another thing to add to my sample solution for Johan...

I noticed a problem when using onRender because my CPU usage went mad for Servoy and caused my fans to kick in on my MBP...
I am trying to use the onRender event to 'highlight' certain fields in a tab depending on record and related record values.
I have tried attaching all logic inside the form onRender and also (instead) in the specific field's onRender, and with the related tab form set as Record, List or Table view, all same problem.
When there is more than one related record, it seems like onRender keeps on getting called in an infinite loop.
If there is no related record it doesn't fire
If there is one related record, it (I think) fires once for each element on form
BUT, if there is more than one related record, it keeps firing round and round (I have put application.output ( ) calls in each onRender to see) and CPU usage goes from <10% to 70-100%!!
The relation is a simple one based on a PK to FK only.
Even if I just display the form on it's own, as soon as there is more than one record, it goes mad.
Here is the code I put ion the onRender (or same code but just with the one condition specific to that field in each field onRender)
Code: Select all
   /** @type {JSRecord<db:/pro_conf/confline>} */
   var $record = event.getRecord ( );
   if ( $record != null )
   {
      if ( $record.confcode == null || $record.confcode == '' )
         elements.confcode.bgcolor = '#ff0000';
      if ( ($record.confinvrecip == 'Y') && ($record.confpaid == 'Y') && ( $record.confpayslip != null && $record.confpayslip != '') )
         elements.confpayslip.bgcolor = '#ff0000';
      if ( databaseManager.hasRecords ( $record.confline_to_corresp_by_booking ))
         if ( $record.confline_to_corresp_by_booking.sageexported == null || $record.confline_to_corresp_by_booking.sageexported == '')
            elements.confinvno.bgcolor = '#00ff00';
         else
            elements.confinvno.bgcolor = '#ff0000';
   }

The relation confline_to_corresp_by_booking is a many-to-one relation , relating all records in that tab to an invoice to check if it has been exported to Sage (an accounts package) [but I just tried turning that test off and it still goes mad]

Have I done something really stupid & not understood how to code for onRender (entirely possible as I'm old school Servoy...)??
Is this a bug? (If so, surely it must have happened for someone else as well????)

Do I need to add this to my sample solution Johan?

Help!

[EDIT I just tried turning off my extra onRender's, leaving just the form one and it doesn't behave as badly i.e. it stops after 'no of recs' x 'no of elements' fires of onRender, BUT if I move the mouse over the records, it fires IF there is more than one record in the tab. I have one element with an onFocusLost event, but firing happens if I move over any element. It does stop firing when I stop moving over elements. Still happens even if I turn off onFocusLost...
/EDIT]

Thanks

Rafi
Servoy Certified Developer
Image
rafig
 
Posts: 708
Joined: Mon Dec 22, 2003 12:58 pm
Location: Watford, UK

Re: onRender infinite loop in tab with more than 1 record

Postby Harjo » Fri May 24, 2013 8:50 am

Don't use elements inside an onRender

the onRender of a form will fire, everytime on each element, field, button etc...
use the event.getRenderable() component to determ, which field or element you have...

here is an example from the wiki:

Code: Select all
/*
* Called before the form component is rendered.
*
* @param {JSRenderEvent} event the render event
*/
function onRender(event) {
/** @type {JSRecord<db:/udm/orders>}*/
var rec = event.getRecord()
if (rec && rec.amt_tax == 0) {
    event.getRenderable().fgcolor = '#ff6600';
} else if (rec && rec.amt_tax < 0) {
    event.getRenderable().fgcolor = '#ff0000';
} else {
    event.getRenderable().fgcolor = '#000000';
}
}
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: onRender infinite loop in tab with more than 1 record

Postby rafig » Fri May 24, 2013 12:16 pm

Hey Harjo!
Harjo wrote:Don't use elements inside an onRender

the onRender of a form will fire, everytime on each element, field, button etc...
use the event.getRenderable() component to determ, which field or element you have...

here is an example from the wiki:

Once again you come to the rescue!
I knew I was doing something wrong :wink:
All better now, thanks!

Rafi
Servoy Certified Developer
Image
rafig
 
Posts: 708
Joined: Mon Dec 22, 2003 12:58 pm
Location: Watford, UK


Return to Discuss possible Issues and Bugs

Who is online

Users browsing this forum: No registered users and 4 guests