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
Developer
onelord2002
Posts: 66
Registered: ‎09-14-2011
My Device: Simulator
My Carrier: Developer
Accepted Solution

GUI or Console output in javascript extension

While working in webworks i user "alert" to know the values of variables and to check on the flow of control.

Now i started writting javascript extension in java

but when ever i tried Dialog.alert("message"); the extension stopes working

 

is it like the javascript extension cannot show any GUI output???

if it is like that can i see those in console???

how can i check variables values???

or when ever i click a button i want to see that the function id being invoked correctly so i used to put alert()

is there anything like that which i can put inside java classes or can print the output on console??

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

Re: GUI or Console output in javascript extension

You may be interested in some of the code that John uploaded for outputting data to the system log.

 

https://github.com/blackberry/WebWorks-Community-APIs/tree/master/Smartphone/systemlog

 

The reason why the Dialog.alert() doesn't work from Java (depending on the extension) is a threading issue.  The JavaScript extension that you are writing is not running in the UI thread.  Thus it can't interact with the display.  you would have to spawn off the Dialog in a different thread that gets synchronized with the UI thread in order to display.

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Developer
onelord2002
Posts: 66
Registered: ‎09-14-2011
My Device: Simulator
My Carrier: Developer

Re: GUI or Console output in javascript extension

so if i create another thread and call Dialog.alert() inside that will that going to work or does it need to be registred as UI thread by extending or implementing something????

 

will this do???

public class VoiceRecord extends ScriptableFunction {
    public Object invoke(Object obj, Object[] args) throws Exception{
        String fnName = agr[0];
        Record rObj = new Record();
        if(fnName.equals("start")){
            rObj.start();
            return new String("Started Recording");
        }
        else if(fnName.equals("stop")){
            rObj.stop();
            return new String("Stoped Recording");
        }
        //if argument is none of the above then
        return new String("NoSuchMethodFound");
    }
}

class Record extends Thread{
    public void run(){
        //code for recording
        DIalog.alert("hi");
    }
   
    public void stop(){
        //stoping the thread
    }
}

 

Please use plain text.
Developer
onelord2002
Posts: 66
Registered: ‎09-14-2011
My Device: Simulator
My Carrier: Developer

Re: GUI or Console output in javascript extension

its not working i did this

 

public class VoiceRecord extends ScriptableFunction {
	
	Recording rObj = new Recording();
	String functionName;
	public Object invoke(Object obj, Object[] args) throws Exception{
		functionName = args[0].toString();
		
		if(functionName.equals("start")){
			try{
				rObj.start();
				return new String("return inside java : ");
			}catch(Exception ex){}
		}
		return new String("no function with that name");
	}
	
}

class Recording extends Thread{
	
	public void run(){
		Dialog.alert("Thread started inside java");
	}
}

 

 it is giving RuntimeException :smileysad:

Please use plain text.
Developer
onelord2002
Posts: 66
Registered: ‎09-14-2011
My Device: Simulator
My Carrier: Developer

Re: GUI or Console output in javascript extension

got it insteed of just calling DIalog.alert i have to do this

 

class Recording extends Thread{
	
	public void run(){
		UiApplication.getUiApplication().invokeAndWait(new Runnable() {
	            public void run() {
	               Dialog.inform("Thread started inside java and this is inside run");
	            }
	         });
	}
}

 

 

Please use plain text.
BlackBerry Development Advisor (Retired)
jeffheifetz
Posts: 518
Registered: ‎07-18-2011
My Device: Bold
My Carrier: Rogers

Re: GUI or Console output in javascript extension

Also if you want to live debug with console you can use WebInspector on 7.0 devices or Weinre on all webworks devices.



1.Please resolve your thread by clicking the "Accept as Solution" button below the post which solved your problem!
2. If any post helps you please click the button below the post(s)
Please use plain text.
Developer
wantoun
Posts: 165
Registered: ‎10-04-2010
My Device: P'9982 & Z10
My Carrier: alfa Lebanon

Re: GUI or Console output in javascript extension

Hello, I think I want exactly what you were talking about. But I'm new to this and I don't think I get how Javascirpt extensions work. Do you mind sharing the code you wrote for the GUI ouput (pop-up) along with what you actually called in the javascript?

 

You can find my code in this thread if that helps explain my problem:

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/HTML5-App-Show-Pop-Up-Window-whe...

 

Any help is really appreciated :smileyhappy:

Wadi
Please use plain text.