webOShelp.net

Get the latest on:webOS Developers' RSS FeedwebOS Facebook page webOS Twitter Feed

Home Forums
The webOShelp.net WebOS / Mojo Developers' Forum
October 25, 2014, 11:38:45 AM *
Welcome, Guest. Please login (using the form in the left column) or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Alert Box in Mojo Code  (Read 4947 times)
lainteract
webOS Newb
*
Offline Offline

Posts: 2


View Profile
« on: August 18, 2009, 02:47:33 PM »

I have been stymied by the absence or apparent absence of debugging tools. When writing conventional Javascript code, I sometimes put alert boxes (alert('string')Wink to display diagnostic debug info. Is this allowed in the mojo framework? I would just try it, but it's hard just to figure out where to put it. Whatever happened to the day  of straightforward Javascript?
Logged
P2Labs
webOS Newb
*
Offline Offline

Posts: 2



View Profile WWW
« Reply #1 on: August 20, 2009, 07:24:25 AM »

In your assistant file...

Code:
function MyAssistant() {
}

add a method like so...

Code:
MyAssistant.prototype.showDialogBox = function( caption, msg ){
this.controller.showAlertDialog({
onChoose: function(value) {},
title: caption,
message: msg,
choices: [{
label: 'OK',
value: 'OK',
type: 'dismiss'
}]
});
}

then call it wherever you like...

Code:
this.showDialogBox( "My App", "Here's a debug message..." );
Logged
sachapma
webOS Newb
*
Offline Offline

Posts: 1


View Profile
« Reply #2 on: August 22, 2009, 05:18:47 AM »

Debugging can be a bit of a problem.  Some hints I've developed:

1) SSH into the emulator on port 5522 (userid root, just press enter for the password) then watch the log as your app runs with the command: log com.mydomain.myapp

2) User Mojo.Log.* to write out messages to the log.  This is better than using alert boxes because you can sprinkle them much more liberally throughout your code.  E.G.
Mojo.Log.info('my message', myvalue)
See the doc for more details and note that if use .info you need to update framework_config.json

3) If you're not sure about what properties might be on an object, use:
Mojo.Log.logProperties(myobject)
to get the entire object dumped (objects within the object are not dumped, they just show as [object object])

4) Simple typos can result in Mojo just stopping to process your app, which can be very frustrating to find.  To help combat this:
a) Make small incremental changes and test frequently so if everything goes horribly wrong, hopefully you have less code to look through.
b) Sprinkle Mojo.Log.* through the code to help determine where the code stopped.
c) If all else fails, start commenting out code until something works
d) use jslint -- it can be added to eclipse relatively easily as an external tool.  I have it configured like this in the Eclipse external tools dialog:
Location: ${workspace_loc}/lint/jsl-0.3.0/jsl.exe
Working Dir: ${workspace_loc}
Arguments: -conf ${workspace_loc}/lint/jsl-0.3.0/jsl.conf -process ${resource_loc}
jslint can be a bit picky, but it can find where you mistyped a variable name, which sometimes will cause Mojo to just silently stop working.

5) If your app just uses Mojo, and not any of the services (e.g. database, send email, location services, etc.), then you can run it in Palm Host and step through the code in Safari.  It's not pretty and I don't care a whole lot for the Safari debugger, but it's better than nothing.  Of course as soon as you start using services it breaks, which means I haven't been able to use it for a good while.

I hope that helps some.
Logged
AbeEstrada
webOS Newb
*
Offline Offline

Posts: 1



View Profile WWW
« Reply #3 on: August 26, 2009, 10:03:31 PM »

5) If your app just uses Mojo, and not any of the services (e.g. database, send email, location services, etc.), then you can run it in Palm Host and step through the code in Safari.  It's not pretty and I don't care a whole lot for the Safari debugger, but it's better than nothing.  Of course as soon as you start using services it breaks, which means I haven't been able to use it for a good while.

How can I run it in Palm Host and step through the code in Safari???

I saw the Palm webcast, and they are using something like: http://localhost:8888/com.mystuff.helloworld

I don't know how to do that.
Logged
mico
webOS Newb
*
Offline Offline

Posts: 3


View Profile
« Reply #4 on: September 28, 2009, 10:45:31 PM »

I had the same question about developing in browser too and got answers here: http://groups.google.com/group/webos-dev-dc/browse_thread/thread/3bdccc18ccaf7984
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2009, Simple Machines LLC
SMF customization services by 2by2host.com
Valid XHTML 1.0! Valid CSS!