views:

318

answers:

4
+4  Q: 

Essential Dojo

I'm starting to use Dojo; this is (essentially) my introduction to AJAX. We have a Java backend (torque / turbine / velocity) and are using the jabsorb JSON-RPC library to bridge Java and Javascript.

What do I need to know? What is the big picture of Dojo and JSON, and what are the nasty little details that will catch me up? What did you spend a couple of days tracking down, when you started with Dojo, that you now take for granted? Thanks for any and all tips.

+4  A: 

I too just dove head first into Dojo, they have a good API documentation at http://api.dojotoolkit.org/. Even Dojo Campus has some good examples of the plug ins.

If you ask me O'Reilly's Dojo: The Definitive Guide is the best Dojo book on the market.

I also would like any tips and pointers from the Dojo masters.

Cheers

d34dIO
+3  A: 

The first thing to do is get familiar with the Dojo Object Model. JavaScript does not have a class system so the Dojo toolkit has created a sort of "by convention" object model that works rather well but is very different to how it works in Java for example.

The reason I suggest getting familiar with it is so you can dig into the code base whenever you start experiencing issues. The documentation available has improved significantly over the past year, but every now and then I find myself having to work out a bug in my code by learning exactly how the Dojo code involved works.

Another tip is to make use of the custom build feature which will significantly improve performance once your application is ready.

As a general tip on DHTML programming, use firebug (a plug-in for Firefox). It allows JavaScript debugging, DOM inspection, HTML editing in real-time and a whole lot more. I've become totally reliant on it now when I'm working in DHTML!

Good luck!

Donal Boyle
Donal: is there a "Dojo Object Model" specific to Dojo, or is it the DOM - Document Object Model - or I am missing something ? Thx.
philippe
It is specific to Dojo and, in their own words, "functions to simulate" a class system. You can read more about it here http://dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-dojo/object-orientation
Donal Boyle
+2  A: 

Make sure documentation you read pertains to as recent a release as possible, since a lot has changed very quickly in the Dojo architecture.

Also a great way to see how some Dojo or Dijit widget is used is to look at the source code for the tests - for example, the DataGrid has poor documentation but the tests show a lot of use cases and configurations.

Sitepen is a good resource for Dojo articles.

Also, read up on Deferred (andDeferredList), as well as hitch() - two extremely flexible and powerful features of Dojo. SitePen has a great article on demystifying Deferreds.

Check out plugd, a collection of Dojo extensions that make some things more convenient or adds some clever functionalities to the language. It's made by one of the core Dojo authors so it's rather reliable. It even brings some jQuery niceties into the framework.

Some more things: look into data stores, they're very useful and a much cleaner way to handle Ajax. DojoX has a lot of nice ones too, just remember that DojoX ranges in how well documented or how experimental the components are. Learn the differences between dojo.byId and dijit.byId, as well as the HTML attributes id versus jsId (again, Sitepen has an article).

Wahnfrieden
Thanks; this is all very helpful.
Carl Manaster
One note, Deferreds are good for making asynchronous processes like Ajax calls behave synchronously, like if you have to wait for some ajax calls to return before going on to the next step.
Wahnfrieden
+1  A: 

A couple of things that caught me when I started writing widgets where:

[Understand what dojoAttachPoint, dojoAttachEvent, containerNode and widgitsInTemplate do][1]

have a firm grasp of closures,

Get your head around deferreds

understand ItemFileReadStore, ItemFileWriteStore and stores in general

You can look at stores like a ResultSet (sort of) as well you can data bind them to widgets.

With these major concepts you can start to put together some compelling applications.

Generally what I do is I build a JavaScript facade around my service calls and then I will scrub the response into a store by attaching the first callback in the facade, that call back converts the results into a store and then returns it. This allows me to not hard bind my services to Dojo constructs (so I can support mobile, etc.) while also retuning the data from the facade in a format that data aware widgets expect.

As well if you are doing Java service development you my want to look into JAX-RS. I started out using JSON-RPC which became JABS-ORB but after working with JAX-RS I prefer it, as it integrates well with JPA-EJB and JAXB.

kls