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
New Contributor
Scarex
Posts: 5
Registered: ‎03-30-2010
My Device: BlackBerry 9550

Javascript Extension and getResourceAsStream

Hi people,

working on widget javascript extension, I'm trying to execute some javascript from Java side, and it's ok.

In particular, I'm trying to load this javascript from a file.

 

In my class extension.example.loader.SampleExtension try to load the file javascript.js which is located under the same package (extension.example.loader) using getResourceAsStream:

 

this.getClass().getResourceAsStream("/extension/example/loader/javascript.js")

 

This operation returning a null InputStream.

 

Is there any issue about compiling? Does widget packager remove not code file?

 

Thank you very much!

Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Javascript Extension and getResourceAsStream

Hi Scarex,

 

You may want to take a look at the source code for the widget templates.  It should give you an idea on how we are pulling out the embedded resources.

 

The full source code for the widget templates is in a "device_templates" directory in the Widget SDK install dir.  This is the full Java Code that gets wrapped around BrowserField and runs a widget.

 

Cheers

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
New Contributor
Scarex
Posts: 5
Registered: ‎03-30-2010
My Device: BlackBerry 9550

Re: Javascript Extension and getResourceAsStream

Thanks tneil,

I looked in the code for a solution to my problem, but according to my understanding the found method (which use BrowserFieldRequest obejct) is related to resource packed in the widget itself (it should be declared in config.xml).

What I need is to load a text file attached to java sources used to compile the javascript extension; in other words I put this file in the source code under device_template folder trying to load it at runtime from java code.

 

Probably this is not possible...

 

Thank you very much.
Scarex

Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Javascript Extension and getResourceAsStream

Yeah.. I don't think you will be able to include it as a resource the way you are trying.

 

You may have to simply include the contents of the .js file in a string variable in your code.  Not nearly as flexible that way, but it may be your only option.

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.