Quantcast

Dojo and Grails - single page app, or multiple pages?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Dojo and Grails - single page app, or multiple pages?

John Moore
I'm part way through developing a Grails application with the user interface built using Dojo. What drew me to Dojo initially was the excellent widget set, promising a much more desktop-like functionality for my web app. As I progress, though, I find myself leaning more and more towards the idea of going the whole way down the AJAX path and have everything based on a single page, with AJAX being used to update the various parts of the page as required, rather than the standard Grails web application approach. I'm curious to hear from anybody else who has been using Dojo extensively in a Grails app. What overall design decisions have you made in this respect? Single-page, standard multiple pages, or somewhere in between?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Dojo and Grails - single page app, or multiple pages?

OverZealous
John Moore wrote:
What overall design decisions have you made in this respect? Single-page, standard multiple pages, or somewhere in between?

While I haven't used Dojo in this way with Grails (yet), I'll tell you one thing I discovered with Dojo on another project:

The more you try to make a one-page app, the more you will wish you had written all of the client code in JS.  Don't mix partial HTML views with partial JS code.  It's a nightmare to maintain, and you find yourself writing little hacks to glue the pieces together.  Don't bother using HTML parsing to generate your forms, either.  It's far too slow vs building the form in pure JS.

Instead, build yourself a helper that can generate forms from JSON structures.

The biggest benefit, by far, is that you can use the Dojo build process to compress everything down into one chunk.  A single, large JS file will download many, many times faster than many smaller files, even if they add up to less bytes.  I don't really like the way the Dojo plugin handles JS builds, because it's slow (every build requires recompressing the entire Dojo library) and somewhat limited (doesn't integrate with Resources), but it does work.

- Phil





Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Dojo and Grails - single page app, or multiple pages?

John Moore
That's very interesting, and very helpful. I'm struggling at the moment with devising a low maintenance way of using this stuff - I can see a lot of really neat ways of doing things with Dojo but I can see maintenance nightmares down the line if I do it wrong.

Are you advising against the idea of the Grails app generating HTML content to assign to divs, etc.? That's what I started off doing, rather than using Grails simply to send JSON data backwards and forwards (that is, I have been generating an HTML table server-side, say, rather than simply fetching the data from Grails via JSON and building the table in the client).
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Dojo and Grails - single page app, or multiple pages?

Rob Meidal
In reply to this post by OverZealous
The grails plugin is good at adding Dojo to an app but I wouldn't use it for a full page app where the app becomes much like a fat client. 

You would be better off creating the majority of your UI in JS files, calling Dojo components directly. You can bring in the dojo library with the plugin but at that point, you would want to write your grid, panels, and other UI elements with JS.  The dojo theme tester might give you some ideas on a starting point: 


On a side note, I agree the build process is slow but you can call "grails install-custom-dojo" that will pre-generate your build. You can check that into your code repo and then turn off the dojo build during war creation. Should help with performance. 

- Rob


On Apr 2, 2012, at 7:49 AM, Phil DeJarnett wrote:

John Moore wrote:
What overall design decisions have you made in this respect? Single-page, standard multiple pages, or somewhere in between?

While I haven't used Dojo in this way with Grails (yet), I'll tell you one thing I discovered with Dojo on another project:

The more you try to make a one-page app, the more you will wish you had written all of the client code in JS.  Don't mix partial HTML views with partial JS code.  It's a nightmare to maintain, and you find yourself writing little hacks to glue the pieces together.  Don't bother using HTML parsing to generate your forms, either.  It's far too slow vs building the form in pure JS.

Instead, build yourself a helper that can generate forms from JSON structures.

The biggest benefit, by far, is that you can use the Dojo build process to compress everything down into one chunk.  A single, large JS file will download many, many times faster than many smaller files, even if they add up to less bytes.  I don't really like the way the Dojo plugin handles JS builds, because it's slow (every build requires recompressing the entire Dojo library) and somewhat limited (doesn't integrate with Resources), but it does work.

- Phil






Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Dojo and Grails - single page app, or multiple pages?

John Moore
Rob, thanks for your input. I have in fact been using a lot of 'native' Dojo stuff of late, rather than features of your excellent plugin, partly because I've been taking advantage of Dojo examples out there on the web, but also because I've felt I've needed to get under the hood a little more. I think Dojo is fantastically powerful and comprehensive, and ultimately will make a great partner with Grails for me, but I now realise it's not something you can nibble at the edges of.  I think it's something you have to understand pretty well to take advantage of, and it's a steep learning curve. The good thing is that everything I've seen so far about it suggests thoroughness and consistency, meaning that once I have properly got my head around its way of working,  I'm confident it will great to work with.

An example area of this thing of going the whole hog is with Dojo select widgets (ComboBoxes, FilteringSelects, etc).  I have a taglib which I adapted from something by Marcel Overdijk. At the moment the select tags use a standard Grails 'from', as in the Grails taglib, but I'm now moving them over to use a Dojo store instead, with a view to being able to simply update the backing store and have the select options automatically be updated. I have to understand the Dojo Store API to be able to do this, but I think it'll be worth it.  All of this is probably a long process but one which will be worthwhile in the end.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Dojo and Grails - single page app, or multiple pages?

mtyson
This post has NOT been accepted by the mailing list yet.
In reply to this post by Rob Meidal
Its worth noting that the build is supposed much faster (thanks to more parallelism) in Dojo 1.7.  I've read reports of it taking 1/3 the time for a build.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Dojo and Grails - single page app, or multiple pages?

manojbhardwaj
This post has NOT been accepted by the mailing list yet.
In reply to this post by John Moore
This is very interesting line of conversation, something I wish to explore more.

John, when you say you are using "native" Dojo stuff, do you mean that you are not using the plugin? Are you directly changing the main GSP files to include/require Dojo files and then creating widgets using either JS or "data-dojo-type"? In short, are you not using the plugin, other than for doing a custom dojo build? This choice of design -- is it for one page app or are you suggesting this approach is more flexible and more maintainable for multi-page app too? Please can you share your experiences.

I am very new to Grails/GSP but have a few months experience tinkering with Dojo (1.6, 1.7 and 1.8).
Loading...