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
Contributor
Posts: 10
Registered: ‎10-04-2010
My Device: Not Specified

Templates do not work on BB5 devices

Hi,

 

I'm trying to use a templating system for building a client-side WebWorks software. I built mainly built it under the Torch, but at certain points also tested it for the Storm and 9700 simulators. The application works fine under the OS 6, but the templating system somehow doesn't work on the OS 5. I stepped through the code, and it seems like the part that's causing the trouble is:

 

$("#main_content").setTemplateURL("tmpl/list_view.tmpl");

 

This is the main call to the template, which fetchs the file in that folder, and displays it in the DIV. The way this is implemented is like so in jTemplates:

 

jQuery.fn.setTemplateURL = function(url_, includes, settings) {
        var s = jQuery.ajax({
            url: url_,
            async: false
        }).responseText;
        
        return jQuery(this).setTemplate(s, includes, settings);
};

 

 

I know that OS5 seems to support AJAX requests. What could be causing the trouble here? Is it because the request is to a local file? Should I set special permissions in my config.xml for that folder? Or should I use a specific URL scheme for accessing local files?

 

Any help would be much appreciated!

Retired
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: Templates do not work on BB5 devices

Are you getting any type of response from the AJAX request, or nothing at all?

 

For local (embedded) file access, try using "local:///tmpl/list_view.tmpl".

 

It may be an issue with jQuery running on OS 5.0.  Although OS 5.0 does have limited support for jQuery, it is not optimized for it and so may observe some glitches.  You can rule this out by defining your own AJAX GET method to retrieve the contents of the *.tmpl file.

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Highlighted
Contributor
Posts: 10
Registered: ‎10-04-2010
My Device: Not Specified

Re: Templates do not work on BB5 devices

Thanks for the reply astanley. I have actually stepped through the code for hours in order to crack this, and I believe I at least know what's causing the problem. It seems that in OS 5, you can't make AJAX queries within the callback of other AJAX queries. Here's what I mean:

 

* In my code, I have a main AJAX queries that requests some JSON from the server. The data returned from the server is passed to the "success" callback of this request.

 

* In this callback, I  pass the returned data as it is to a template through setTemplateURL. This is the part that doesn't work.

 

When I isolate setTemplateURL in the main line of code (not in a callback), it works, so the issue shouldn't be with AJAX, or with config.xml. This whole scheme works in OS6 though.

 

So now that I have found the reason for this, I need to come up with a way of overriding this, since I really do wish to use templates on AJAX queries. Any ideas?