Monday, December 19, 2011

You Can't Spell Forge Without Metawidget

JBoss have just released Beta 4 of JBoss Forge. There are a host of new features in this release. Most exciting for me being the new UI scaffolding.

Scaffolding has been significantly rewritten to use a new static Metawidget. This allows Forge to output pure JSF tags, with no runtime dependencies on any non-Java EE libraries. The UI includes creating, updating, deleting, pagination and searching. It also supports one-to-many, many-to-many, many-to-one and one-to-one relationships:
The code it generates is very clean:

<h:panelGrid columnClasses="label,component,required" columns="3">
   <h:outputLabel for="customerBeanCustomerFirstName" value="First Name:"/>
   <h:panelGroup>
      <h:inputText id="customerBeanCustomerFirstName" value="#{customerBean.customer.firstName}"/>
      <h:message for="customerBeanCustomerFirstName" styleClass="error"/>
   </h:panelGroup>
   ...

Behind the scenes, Forge is still using the same Metawidget pipeline as before - the same Inspectors, WidgetBuilders, WidgetProcesors and Layouts. This means the scaffolding is pluggable to adapt to your needs - including custom UI libraries, custom layouts, even custom langauges (Ceylon, anyone?).

The new static Metawidget is also used to generate Java code for the JSF backing beans. Again using WidgetBuilders and outputting very clean code:

String firstName = this.search.getFirstName();
if (firstName != null && !"".equals(firstName)) {
   predicatesList.add(builder.like(root.<String>get("firstName"), '%' + firstName + '%'));
}
String lastName = this.search.getLastName();
if (lastName != null && !"".equals(lastName)) {
   predicatesList.add(builder.like(root.<String>get("lastName"), '%' + lastName + '%'));
}

Please give it a try!
  • Download Forge Beta4

  • Install it

  • Run it

  • Copy and execute this command:
    $ run-url https://raw.github.com/forge/core/master/showcase/posale.fsh
For the lazy, I've uploaded the project that Forge generates. You can download it here.

Sunday, December 4, 2011

Pleasing Dick Wall

In Episode 371 of the Java Posse, Dick Wall has this to say about D.R.Y. (at 47m.30s):

"That actually, I hate to say, but it's an affliction that's very very bad in the Java world. And you see developers drop it as soon as they see another programming environment and really grok the idea of Don't Repeat Yourself. A lot of the flagship libraries in Java are really bad for this.

Wicket is one that springs to mind... everybody loves Wicket, [but] now I've been exposed to a bunch of different stuff I look at it and you have to repeat things 3, 4 or 5 times sometimes. When you're adding a field on to a Web page you've gotta name it on the page and then you come into the code and you write your handle on it with the exact same kind of component that is, and the name, and even worse, you know, taking the current Java mindset of 'you should be working for the compiler' and not the other way around.

If you get it wrong, it complains at you. It doesn't try and fix it for you."


This is, of course, exactly the problem that Metawidget is designed to address. I talk about it in my JavaOne video here (at 5m.30s).

Unfortunately work has stalled on the Wicket version while I've been working on JBoss Forge integration. Wicket actually makes completely dynamic controls, like Metawidget, tricky because of its approach of 'a Java file and a static HTML file'.

However, I was fortunate to have lunch with Wicket guru Juliano Viana at JavaOne 2011. He deep dived into the Wicket internals and found MarkupContainer.getAssociatedMarkupStream for me. It looks like this can free up the requirement of a static HTML file. So hopefully there is a way to get around this Wicket limitation.

Thursday, December 1, 2011

Metawidget @ JavaOne 2011: JBoss Booth Video

JBoss have posted videos from sessions at their mini-theater in the JavaOne Exhibition Hall. This includes our talk on DRY UIs: Let the metadata do the work:



The video is available in High Definition, so please try the Full Screen mode if you find the coding examples difficult to read. A very similar talk, given as a JavaOne conference session, is available on Parleys.

Tuesday, November 8, 2011

Should HTML.next Have A Higher Level of Abstraction?

HTML brings a lot of great features to the table. One of them is device independence. The HTML author gets to write:

<button value="OK"/>

And the device gets to choose how to render that using a native widget:

I think this is a great level of abstraction. But in my opinion the W3C made a mistake when they specified:

<input type="checkbox"/>

See that type attribute? It's referring to the widget type. But it really should be referring to the data type. Then we could write:

<input type="boolean"/>
<input type="date"/>
<input type="integer"/>
<input type="color"/>

And the device gets to choose how to render that. If it were a simple device, or it didn't understand the data type, it could just render a text box. But better implementations could offer nicer UIs. Date pickers. Spinners. Color pickers. Browsers could compete by offering better widgets.

Think how much time our industry has wasted re-implementing HTML date pickers and spinners. Hundreds of widget libraries across all development platforms (PHP libraries, Java libraries, .NET libraries, etc).

I came to this realisation while using Metawidget. Typically you tell Metawidget to generate an entire form, composed of many widgets:

<m:metawidget value="#{myForm}"/>
...which gives...

But I've found it suprisingly useful to still use Metawidget even when dealing with single widgets:

<m:metawidget value="#{myForm.name}"/>
<m:metawidget value="#{myForm.age}"/>
<m:metawidget value="#{myForm.dateOfBirth}"/>

Here we are deferring the actual widget choice to Metawidget. So Metawidget can choose it for us based on the best widgets available on the target device, our locale, our accessibility requirements etc. Maybe that's a plain text box. Or maybe it's a RichFaces date picker. Or an ExtGWT spinner.

It's nice to defer that choice, because now all the widgets can automatically upgrade over time as the platform improves. If this were in HTML too, it'd save an enormous amount of re-implementing. And it would provide a new battleground for browser competition.

Better for developers. Better for browser vendors. Better for consumers.

Sunday, October 30, 2011

Metawidget Quotes

A collection of quotes people have said about Metawidget:

  • "I finally had a chance to try out Metawidget on an example of my own and it is quite amazing"
    Dan Allen (author, Seam In Action)

  • "Looks impressive... the author of this library has evidently put some real thought into this"
    Michael Klaene (Java Developer)

  • "I spun up the SwingMetawidget, very impressive. Love the annotations, too. Thanks a lot for this API! I am going to try one of the web widgets next"
    i k (Swing Developer)

  • "We have a large GWT app it could certainly do with this for the forms. The documentation looks very good. I also really like the 'don't take over the GUI' principle"
    David Tinker (GWT Developer)

  • "This looks like a very interesting project!"
    Johan Andries (Java Developer)

  • "I strongly agree that UI duplication is mindless, error-prone code that should have been solved years ago. I am so glad someone is addressing this"
    Survey respondent

  • "On my todo list is to develop an integration with Metawidget. I'm impressed by the work they're doing here"
    Dan Haywood (author, Domain-Driven Design using Naked Objects)

  • "Metawidget is worth taking a look at"
    Eric Rich (Java Developer)

  • "I have taken a look at it, and found it's a wonderful tool. When coding with SWT, I always wanted to find such kind of tool..."
    Zhong Nanhai (SWT Developer)

  • "Sounds impressive. I was infact looking for such a utility for a while"
    Shashi Ayachitam (Java Developer)

  • "Developers no longer have to spend too much time to bind UI with POJO"
    Vinay Saintantonyar (Java Developer)

  • "The strength of Metawidget is it allows the developer flexibility to change how the front-end is rendered because Metawidget does not exclusively own the front-end like many other frameworks"
    Mark Ashworth (Java Developer)

  • "Metawidget is very interesting... I will try to use it in one of my projects"
    Adam Bien (author, Oracle Java Developer of the Year)

  • "Think of a configurable form widget driven off of your beans through runtime inspection of properties, getters and setters, annotations, etc"
    Dietrich Kappe (Java Developer)

  • "Our app has over 300 screens and UI duplication is a huge maintenance issue for us. You are definitely on to something here and I like the fact that your framework integrates with others and does not try to 'own' the UI"
    Survey respondent

  • "I think Object Interface Mapper (OIM) is a very good 'concept' for this domain. I usually call it 'domain model framework' or something like that, but now I think OIM is more clear"
    wangzx (Java Developer)

  • "In the past I used [other frameworks] but their approach is too invasive and unfittable. Metawidget is very flexible and integrates an environment already in production. Great great great framework!!!"
    Nicola (Java Developer)

  • "Here's something different... it builds on your underlying framework and so is not competing with it"
    Sachin (Java Developer)

  • "I have long held the reason for the incessant churn in how we best complete the UI architecture task is due to the continued quest for economic value. [Your work] shows there are benefits to separating the elements of that task from that churn"
    Ed Burns (author, JSF specification lead)

  • "I have been using Metawidget (which is a really cool library by the way) on a project lately..."
    Arthur Peters (Swing Developer)

  • "Metawidget not only provides a nice UI framework but offers realistically implemented connections to backends"
    Fred Grott (Android Developer)

  • "It works, beautifully! Thanks for bringing us this powerful stuff
    Phaderm (Swing Developer)

  • "Metawidget concept is the way to go.... you can exploit multiple UI targets with minimal code rewrite and take advantage of native widgets when required"
    Steven Goldsmith (Java Developer)

  • "I'd like to thank you for what you've done with Metawidget. It's a really great framework and is proving especially useful in a model driven architecture we are implementing"
    Ashlin Eldridge (Java Developer)

  • "Metawidget is a super-cool project"
    Baruch Sadogursky (author, Spring in a Nutshell)

Monday, October 10, 2011

Metawidget @ JavaOne 2011 (Epilogue)

I had a great time presenting Metawidget at JavaOne 2011. We had a good turn out (about sixty people) with lots of good questions at the end. My thanks to all who attended, and to my co-speaker Dan Allen.


The full talk should be available on Parleys in the next few weeks.

Tuesday, September 13, 2011

Metawidget @ JavaOne 2011 (Updated)


The time and venue for the Metawidget technical session at JavaOne 2011 have now been confirmed:

DRY UIs: Let the metadata do the work
Date:Wednesday 5th October 2011
Time:1:00 PM
Speakers: Dan Allen, Richard Kennard
Venue:Parc 55 - Market Street
Length:1 hour
Track:Emerging Languages, Tools, and Techniques

How many times have you sat in a dark office after hours hand editing forms, page after page? Software teams spend a lot of time developing the UI. To speed up the process, developers resort to drag-and-drop widget solutions or model-based static generation tools. These approaches only change the appearance of the problem.

This talk presents Metawidget as a solution to keep your UIs DRY. Metawidget is a smart UI processor that populates itself, at runtime, with UI components that match properties of your model. Rather than introduce new technologies, it reads existing metadata (e.g. JavaBeans, annotations, XML) to create native UI widgets (e.g. JSF, Android, Swing).

Stop hand-coding your forms! Come learn how to break out of the rut!



I'll also be doing a supplemental session at the JBoss booth at 11.30am on Tuesday 4th, as well as being on-hand to answer questions and give live demonstrations.



My thanks to Lee Judaya who put together a cool looking promotional flyer for the sessions.