Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Regular Contributor
lorax1284
Posts: 61
Registered: ‎06-14-2010
My Device: Z30
My Carrier: Virgin Mobile Canada
Accepted Solution

Problem with BBUI / Web Database / asychronous timing: query formatted as HTML not processed by BBUI.js

I think I've solved most of my problems with getting my data to be usable in various functions etc... but by problem now (which may have been the fundamental problem all along) is related to the asychronous nature of Web Database processing.

 

I get my markup back as a <div> with all the 'data-bb-type' etc. attributes, but based on the "alert" statements I have sprinkled throughout my code, the database results are processed after the "onscreenready" event has finished and "ondomready" has started.

 

I know that if you're going to generate markup for use with BBUI.js, it has to go into the "screen" before the "screen" is passed to BBUI.js so BBUI can do all it's fancy stuff to it.

 

I've tried to make sense of it, but it eludes me. Perhaps someone could point me in the right direction for a good tutorial that explains in some clear way what is going on behind the scenes and then I guess I'll have to rip my code apart and put it back together... or at least call functions in a different way or from a different place, or use callbacks more liberally (I'm not exactly clear on use of callbacks either).

Please use plain text.
Regular Contributor
lorax1284
Posts: 61
Registered: ‎06-14-2010
My Device: Z30
My Carrier: Virgin Mobile Canada

Re: Problem with BBUI / Web Database / asychronous timing: query formatted as HTML not processed by BBUI.js

[ Edited ]

BUMP. I've seen easy-to-understand code for reading SQLite... I've seen easy-to-understand code for interacting with existing BBUI.js objects... I haven't yet found any sample code that hits a SQLite database for a given BBUI "screen" and then fills that screen with objects derived from the SQLite database result. Is there any sample code that fetches the data via SQLite query and processes it into BBUI.js-compatible markup all within the 'onscreenready' event?

 

Is it possible that I should perform all my 'bulk' queries in the initApp function (pull all the data from all the SQLite tables into objects, ready to process) when the app launches, then in "onscreenready" just process the object into the markup?

 

I think that approach would work, but I think I'm right in trying to avoid an approach that is "top heavy" and I think I want to rule out other (what I think are very likely) more correct approaches before I resort to basically bringing the entire SQLite database into memory and keeping it there / interacting with objects AND the database at every turn.

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Problem with BBUI / Web Database / asychronous timing: query formatted as HTML not processed by BBUI.js

The approach you're describing would be necessary in the sense that an asynchronous call within the onscreenready function will allow that function to progress / likely complete, and BBUI continues on processing before you can fully modify the elements with data returned by the database.

Front-loading the content, while not ideal, is a valid route.

The other option, depending on which time of control you are populating, would be to wait for ondomready, and then use the JavaScript APIs for the control (if it has any) to populate it after the fact. For example, ImageList controls have JavaScript APIs to refresh their content with an array of items, after the element has been created / BBUI-ified.

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Regular Contributor
lorax1284
Posts: 61
Registered: ‎06-14-2010
My Device: Z30
My Carrier: Virgin Mobile Canada

Re: Problem with BBUI / Web Database / asychronous timing: query formatted as HTML not processed by BBUI.js

Thanks very much for this advice; that is the approach I am going to take (preloading), unless there is a way to do the database queries synchronously... But I will try preloading and if the performance suffers significantly I will do the query and rendering in the ondomready event.
Please use plain text.