So we managed to sneak one additional feature into the upcoming Appcelerator 2.1 release. Those of you developing for the iPhone will be pleased to know that we added a new condition - ‘orientationchange’ - so you can handle the origintationchanged event on the iPhone in an on-expression. How cool is that? Very. So throw this onto the pile with the new build process, project command line tools, the eclipse plugin/ide (written by Mark Luffel), the developer network (it’s slick — just wait’ll you see it), and a ton of little features and fixes all over the place. Not to mention improvements to a bunch of the widgets (like the datatable which now supports custom formatter functions, sticky sort, etc.).
Popularity: 7% [?]
Purpose
The Appcelerator framework allows for the extension of the build and deployment process so that you can add components and modify the behavior of your service implementations. It is quite powerful and not only restricted to services, plugins for example could span across to the modification of applications and the entire build and deployment process for that matter. For simplicity, this article will identify how to create a new component added to our java service for monitoring performance.
Install Appcelerator
I’ve assumed that you’ve successfully downloaded and installed Appcelerator from http://www.appcelerator.org/products. Once you’ve gone through the installer you can get the java service
1
| app install:service java |
You may wan to get an existing plugin:
1
| app install:plugin java:spring |
Plugin Creation
Lets assume that our plugin is going to be called java:perf, to create the plugin project:
1
2
| cd $HOME/workspace
app create:plugin . java:perf |
This will create a sub directory named java_perf, now you will want to create a proper license entry in your build.yml for example check out build.yml. You now ave the opportunity to modify the entry points in your java_perf.rb. I personally wanted to setup my install script so that:
- dynamically builds the jar when we add the plugin to a project
- modified the spring.xml to include the bean entries for my component
All of this is in before_add_plugin(event) callback. If you want to see where this is called, check out add_plugin.rb. Once my coding is complete (added my source files to java_perf/src), I created the plugin distribution:
Install the plugin
As you noticed, I haven’t covered debugging the plugin just yet, this is because i want to first set up the plugin for installation and then work with it in my install directory. Lets install it to my local machine:
1
| app install:plugin java_perf.zip |
Add the plugin to my project
I thought that I’d create a blank java project real quick
1
2
| cd workspace
app create:project . myproject java |
now we can add the spring plugin and our new java:perf plugin to our project
1
2
3
| cd myproject
app add:plugin java:spring
app add:plugin java:perf |
You can now directly modify the java_perf.rb file in your install directory
- windows: c:/Program Files/Appcelerator/releases/plugin/java_perf/1.0
- unix: /usr/local/Appcelerator/releases/plugin/java_perf/1.0
- mac os: /Library/Appcelerator/releases/plugin/java_perf/1.0
I suggest that you continue to modify the java_perf.rb this way to debug it and then finalize by copying back over to $HOME/workspace/java_perf
Next Steps
As a final parting you can release your new plugin so that others may be able to leverage it
1
2
| cd $HOME/workspace/java_perf
app release java_perf.zip |
Popularity: 8% [?]
Purpose
The ability to debug applications is critical when things go sideways on you. I understand that for some of the developers out there learning a new framework can be challenging. Appcelerator provides developers with the tool-set to drastically reduce the amount of javascript code that they need to write and to be honest I think that the more you use the framework, the less you will need to debug applications as you familiarize yourself with the syntax.
Alerts
Prior to logging, alerts were the best way to display state during execution (showing you how old school I’ve been). Nonetheless, sometimes this is just easier since it blocks execution until you confirm. When you do this, you may want want to display objects. Lets take for example the following
You make get an alert that shows:

Well that isn’t very useful. If you want a nice string representation, use the following
1
| alert(Object.toJSON(myobject)); |
Now you’ll get a nice JSON representation.

Logging
Safari and Firefox both provide you with the ability to view logging in the console. For firefox, you need to install firebug. If you are a safari user, you can use webkit (from the Debug menu, click “Show Javascript Console”). Both of which make available a console that displays log statements.
In firefox you can do the following in javascript
I suggest however that you dont do that! Instead make use of the abstracted Logger
This will not only show up in Firefox, but also in Safari’s console.

On another note, you can use the debug=1 parameter in your URL and you will see a ton of appcelerator messages (ex: http:localhos:8080/myapp?debug=1). I will caution you that it will almost look like spam given the amount of detail that is logged, but nonetheless its there if you want it.
You can also expand the Get and Post statements in firefox which will let you know what you have sent in your request and the JSON result that was returned from the server.

In-line Debugging
Lets say that you have an error in your app:script. Well in Firefox, you can take a look at the console and that will give you some pretty good feedback, however its going to be some cryptic text and you can’t step through it. You have 2 options that will enable you to step through the code:
- can make a call to a javascript function from your app:script (I normally define a project specific javascript file and put my functions in it)
- define a $MQL in your javascript file - app:script goes away
Here is scenario 1:
1
2
3
| <app:script on="r:someevent.response then execute">
Myapp.dosomething(this.data);
</app:script> |
and the corresponding javascript
1
2
3
4
5
| Myapp = Class.create();
Myapp.dosomething = function(data)
{
//code here
} |
For scenario 2: alternatively you could just define in your javascript file
1
2
3
4
| $MQL('r:someevent.response',function(type,msg,datatype,from)
{
//code here
}); |
The downside of this is that your implementation is not colocated in a single html file, but the upside is that you can debug it. Note that if you are not using content files, then you could alternatively define the above in a script element instead (a little cleaner), however if its a large app, then you really will want to decompose your app and use content files.
IE Specific Debugging
To be honest I’m not a huge IE fan, but it makes up an install base of 80% of the market. Chances are that pretty much everyone out there is using IE if you are building an application that appeals to the general public. To this end, Microsoft has made the .Net Developer Studio available for debugging your applications. The steps are pretty simple:
- install .Net Studio and create a project
- add your javascript files to your project
- start IE with your app’s url
- in Visual studio, select debug process and select your iexplorer.exe (sometimes it wont attach, but just keep trying and you should get there eventually)
For understanding styling, I suggest downloading the Internet Explorer Developer Toolbar. This will allow you to inspect individual elements (using the hover) and then setting styling attributes on your elements. This is much better than changing your html and reloading your page, especially for large applications.
Firefox (Firebug) Specific debugging
As with IE, you can use the firefox plugin to step through your code.
- load your app
- open firebug
- click script and select the html or javascript file and set your breakpoints
As with IE, using the Inspect module in firebug is very useful for styling your application.
Wrap Up
In this article we covered a bunch of ways that you can get down to the details in your application
- alerts (and displaying objects as strings)
- logging (appcelerator debug mode, custom log statements, ajax payloads)
- in line javascript debugging and styling
For many this may be an obvious repeat of the mechanisms that they currently use as web developers, but hopefully it will uncover some of the tactics that are used.
-andrew
this blog is cross posted at:
http://zuerchtech.com/2008/2/21/debugging-appcelerator-applications
Popularity: 6% [?]