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:inputText id="customerBeanCustomerFirstName" value="#{customerBean.customer.firstName}"/>
      <h:message for="customerBeanCustomerFirstName" styleClass="error"/>

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 =;
if (firstName != null && !"".equals(firstName)) {
   predicatesList.add(<String>get("firstName"), '%' + firstName + '%'));
String lastName =;
if (lastName != null && !"".equals(lastName)) {
   predicatesList.add(<String>get("lastName"), '%' + lastName + '%'));

Please give it a try!
  • Download Forge Beta4

  • Install it

  • Run it

  • Copy and execute this command:
    $ run-url
For the lazy, I've uploaded the project that Forge generates. You can download it here.


Yeroc said...

Is this implemented in a similar manner to the GWT integration which uses some sort of compile-time code generation to workaround the lack of runtime-reflection in GWT? Also, I'm curious if SeamForge supports GWT?

Richard said...

There are a few dimensions to your answer:

1. The runtime GWT Metawidget, which works at runtime and does not use any static code generation: yes, it uses 'some sort of compile-time code generation to workaround the lack of runtime reflection'.

2. The static JSF generation (described in this blog): no, is purely a static solution, so it just generates normal JSF tags

3. Forge supporting GWT: not yet. Please get involved!



Anonymous said...

the download link doesn't work

Richard said...

Apologies. Link now fixed.

Dan Allen said...

Richard, the UI looks really nice. I saw it for the first time while giving a demo of it (yes, you heard that right, preparation is a luxury).

I immediately appreciated the smooth transition from search criteria to creating a new entity. I've never seen that workflow before (that I can remember), and yet it felt very natural. The expandable form for creating a new related entity was also a nice surprise.

I was also pleasantly surprised by the select menu fields in the search query. Typically search fields are much less helpful. I can see dropping in a RichFaces component to get autocomplete for mile long lists.

Keep up the great work! The quality of your work is being more than noticed.

Richard said...

Thanks Dan for your kind words.

It's easy to do a nice job when the people you're working with make it so much fun!

Anonymous said...

Thx for the gerat post, the gerat implementation to get clean jsf code. Forke and metawidget is a great combination!

If not putting the metwidgets annotations into the bean (so no dependencies are in runtime) where shold I put some metawidgets layout hints for attributes/items (e.g. PlaceAfter, etc) during the scafford?

Richard said...

This area of Forge still needs a bit of work. will make it much easier to hook into Metawidget. At the moment you will need to extend the scaffold plugin.

But, once hooked in, you can use metawidget-metadata.xml as usual. For more information, please take a look at the Metawidget tutorial:

Anonymous said...

Thx for you answer and the link. Just can proove what you mentioned there: "This idea of combining multiple Inspectors to inspect different characteristics of your existing architecture is very powerful!" Thats the right way foreward,