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

Java Development

Reply
Developer
5020379021
Posts: 50
Registered: ‎02-18-2009
My Device: Not Specified
Accepted Solution

browserField.executeScript

Hi,

 

I'm stuck by an issue about adding a browserFieldListener. I have an BlackBerry native application accessing a web application by using the browser. I have a block of javascript in a certain page. I want to use browserField.executeScript("my javascript in a JSP") and to check the return boolean value when I request for every page. So I overwrite the documentLoaded method and add the executeScript method in it. However, It always throw IllegalStateException when doing browserField.executeScript. After I review the RIM API, I found it refers to the exception as "IllegalStateException - this exception is thrown if this method invoked before this BrowserField's document has been created. This event is communicated via the BrowserFieldListener.documentCreated() method." Does anyone have any suggestions or comments here, please? Thanks a lot.

Please use plain text.
Developer
maadani
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: browserField.executeScript

Just a thought, have you enabled JavaScript in your browserField?

 

E.

Please use plain text.
Developer
5020379021
Posts: 50
Registered: ‎02-18-2009
My Device: Not Specified

Re: browserField.executeScript

Thanks for your reply and yes, I do enable the javascript in BrowserFieldConfig.

Please use plain text.
Developer
5020379021
Posts: 50
Registered: ‎02-18-2009
My Device: Not Specified

Re: browserField.executeScript

I finally figure this issue out. It is wrong to do the excuteScript method in documentLoaded() of BrowserFieldListener since scripts in the document cannot be invoked before the document gets loaded. I think it makes sense. So if you want to do any stuff like read the DOM of invoke the javascript of your document, Be sure the action happens after the whole document gets loaded. The original purpose of my code is sort of like: use browser to open a web page, check some flag from that page, generate a custom browser menu dynamically according to this flag. So now, I put all this reading document action into makeMenu method and this would make sure all the action happen after the page gets loaded.

Please use plain text.
Contributor
haga_rakotobe
Posts: 11
Registered: ‎05-21-2012
My Device: multi-device (developer)
My Carrier: multi-provider (developer)

Re: browserField.executeScript

My understanding was that documentLoaded() of BrowserFieldListener is meant to notify that the whole document was loaded...What are the recommended ways to execute code right after the whole document is loaded  and ready to accept javascript?

Please use plain text.
Administrator
MSohm
Posts: 14,241
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: browserField.executeScript

This looks like an event thread issue.  You could work around this by wrapping the executeScript block called in documentLoaded() in an invokeLater() call.  Just ensure that you aren't calling a long running script.

 

UiApplication.getUiApplication().invokeLater(new Runnable()
{
	public void run()
	{
		//execute script here.
	}
});

 

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.