Back around New Years I was looking for a way to simplify creation of cross-browser, DDA accessible HTML. Screens basically. They had to be very rich with lots of bells and whistles and they had to perform. Ideally this system had to be so simple to use that a non-technical person could create XBrowser, DDA compliant screens. I decided to take a second look at ExtJS and it has come a long way since I’d seen it last.
Using ExtJS you can create a screen programmatic-ally using classes and method calls but one of the neat features is that a screen can be entirely described declaratively in JSON notation. Declarative UI is nice, but a meta-data driven UI is nicer. I’ve created such systems in the past but always had to spend so much time maintaining the thing that interpreted the metadata (Sapient Powerbuilder Framework anyone???).
With ExtJS this could be avoided by just serializing the JSON into a database and back again. Eureka! I had a pretty nice metadata driven declarative UI with MINIMAL investment in “framework” code. Minimal investment in this type of “framework wrapper stuff” corresponds to a good upgrade path, quick time to market and very low likelihood that my “metadata wrapper” would break anything in the underlying ExtJS library.
Intrigued and not wanting to practice “architecture space exploration” [LINK] I wrote a proof of concept and built some screens out of metadata.
<rant>Just a second, hey, why did I do this? Well I like to know what I’m talking about. If I’m going to be responsible for something I want to know it’s going to work BEFORE we start. I don’t want to be an architecture astronaut who just reads the brochure. Everyone can read the brochure. I wouldn’t follow someone like that and I don’t expect my team to. </rant>
Enter Ext GWT, Smart GWT (formerly GWT Ext) and MyGWT. Seems everyone has a GWT library, never a good sign imho.
GWT needs to know every execution path at compile time and hence it doesn’t support reflection. First problem was how to paint the screens from metadata. This can be achieved with GWT.create() but wiring the widgets to Java code with string literals is not possible.
In my use case, the developer should configure the metadata, the framework should paint the screen, the developer should write some Java code for screen logic, then wire the two together. There’ll be 300+ developers worldwide of varying experience levels so it’s gotta be simple to use.
I looked at Deferred Binding; “Deferred Binding is Google Web Toolkit’s answer to Java reflection.” BINGO!!! that’s got to be exactly what I’m looking for, it even says “reflection” on the box.
One way to think of this is as “dynamic class-loading that occurs at compile time instead of execution time.” When the GWT Compiler compiles your Java application, it determines all the different “idiosyncrasies” that it must support, and generates a separate, tightly streamlined version of the application for that specific configuration. For example, it generates a different version of the application file for Firefox than it does for Opera.
It’s probably pretty clear by now that Deferred Binding works a little differently than standard dynamic binding. Conceptually, though, the two concepts are fairly similar, and in practice all you usually need to do is just substitute a GWT method for a Java Reflection method. Instead of Class.forName(“MyClass”) you use GWT.create(MyClass).
So although Deferred Binding is the GWT’s answer to reflection, you cannot invoke a method using a string literal, you cannot create a class unless it’s known at compile time and you cannot hook up to an event without compile-time knowledge of the handler.
This makes metadata a pretty tough proposition. To add to the frustration, examples for Deferred Binding were so thin on the ground that it took me 2 evenings to get something working. I’ll post an example in the coming days to “pay it forward”.
Generators could work. Using Generators would possibly allow the creation of a metadata UI framework however, it would take an enormous amount of fairly skilled coding to make this happen. They’d also be very brittle and tough to build; e.g. you have to write out java code using the GWT equivalent of a printf. You’ve no way of knowing if the code will run or not until it’s too late. Certainly very little chance of testing it. Rocket [LINK] claims to fix this problem but frankly this project is far too immature to be of any use.
Gwittir [LINK] is another option that claims to support Reflection. That’s dependent on GWTx and Google Gears. One of my pet-peeves about the open source world is all the dependencies. Don’t make me download 10 other things/frameworks just to draw HelloWorld. GGears is not an option for me so Gwittir is out.