How to determine if a Widget is loaded

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
jyoung
Posts: 642
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

How to determine if a Widget is loaded

Post by jyoung » Wed Dec 21, 2016 7:53 am

I have a widget that renders a Google bar chart.

After I get some data from the ServerModule, I push that data into the widget to display the chart.

Locally this all works great. When I deployed it to our development IBM i server however, I get fatal error that states
Can't access a widget before it has completed loading
How do I determine if the widget has finished loading?

dannyoorburg
Posts: 152
Joined: Mon Jan 04, 2016 9:50 am
Location: Australia

Re: How to determine if a Widget is loaded

Post by dannyoorburg » Wed Dec 21, 2016 8:00 am

You'll have to wait for the Initialize event to fire on your Widget instance...

So whatever code you have now to populate it should probably be in the #MY_WIDGET.Initialize event routine.

Cheers,
Danny

jyoung
Posts: 642
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: How to determine if a Widget is loaded

Post by jyoung » Wed Dec 21, 2016 8:39 am

Thanks for the info on the widget.

I ended up creating a timer to handle it.

First thing I do is define a field to hold whether or not the widget is initialized and capture it in the Initialized event

Code: Select all

define field(#ChartInitialized) type(*BOOLEAN) default(False)
evtroutine handling(#MOBBarChart.Initialize)
#ChartInitialized := True
endroutine
When the ServerModule completes, I check that field, if the chart is not yet initialized, I kick off a timer.

Code: Select all

evtroutine handling(#FindYearlyGrossMargin.Completed)
#SYS_APPLN.TraceMessageText( "FindYearlyGrossMargin Completed" )

if (#ChartInitialized = False)
#WidgetTimer.Start
else
#COM_OWNER.PopulateChart
#COM_OWNER.ToggleChart( True )
endif
endroutine
Then each tick of the timer, I am checking if the chart is initialized.

Code: Select all

evtroutine handling(#WidgetTimer.Tick)
if (#ChartInitialized)
#COM_OWNER.PopulateChart
#COM_OWNER.ToggleChart( True )
#WidgetTimer.Stop
endif
endroutine
I should probably put in a tick count or something to show an error message instead of just waiting.

dannyoorburg
Posts: 152
Joined: Mon Jan 04, 2016 9:50 am
Location: Australia

Re: How to determine if a Widget is loaded

Post by dannyoorburg » Wed Dec 21, 2016 9:22 am

I usually use 2 booleans to do pretty much the same thing...

Code: Select all

Define Field(#ChartInitialized) Type(*BOOLEAN) Default(False)
Define Field(#DataLoaded) Type(*BOOLEAN) Default(False)

Mthroutine Name(PopulateChart)

If (#ChartInitialized *And #DataLoaded)

* Populate Chart

Endif

Endroutine
and then just call the method from both event handlers after setting the appropriate boolean. The last event to fire will trigger the actual load...

Danny...

Post Reply