Gwt Hogan is a templating solution for GWT
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Gwt Hogan


GwtHogan is a templating solution for GWT.

It changes the Gwt paradigm of widget based code and brings a more jquery + templates approach to coding while maintaining the power of GWT/Java as a strongly typed language and very efficient javascript compiler


  • Generator which pre-compiles the templates
  • Can work with Native Java Object data or JSON object data
  • Can manipulate the template and add widgets to the template using GQuery

Getting started

  • Check out the source and run 'mvn clean install'
  • Change directory into the examples directory, and run mvn gwt:run


Use the following maven dependency. NOTE: there's no distribution, so for now you'll have to use your local repository.


Add the following to your gwt.xml file:

<!-- required for gwt-hogan -->
<inherits name="" />
<!-- required for doing jquery like expressions --> 
<inherits name=''/>
<!-- required for passing java objects to templates -->
<inherits name=""/>
<!-- include gwt-hogan -->
<inherits name="com.villagechief.gwt.hogan.gwtHogan" />

The HoganWidget:

A template is made up of 2 components, the html mustache file and a Java class. For example:

public class MyTemplate extends HoganWidget {
  public Test(){
    addParameter("planet", new JSONString("world"));


Hello {{planet}}

MyTemplate can then be used like any other widget. But it MUST be constructed using GWT.create. For example:

MyTemplate myTemplate = GWT.create(MyTemplate.class);

Adding Widgets must be done after the widget is loaded onto the page. You can use GQuery to provide a selector to the add function which will be the container


Click this button: <span id="button"></span>

public class MyTemplate extends HoganWidget {
  public void onLoad(){
    add(new Button(), $("#button1"));

Using Java Objects:

Gwt Java objects need to be managed by the Gwt AutoBeans framework. See for more details.

AutoBeans and Managed java objects can be passed as parameters to a HoganWidget

Data object:

public interface TestData {
    public String getField1();
    public void setField1(String v);


public interface TestDataFactory extends AutoBeanFactory {
    AutoBean<TestData> data();

public class MyTemplate extends HoganWidget {
  public Test(){
    TestDataFactory beanFactory = GWT.create(TestDataFactory.class);
    TestData test1 =; //get a managed TestData object

    addParameter("data", test1);


Field1: {{data.field1}}

Event Handling and DOM Handling

A HoganWidget doesn't contain widgets the way a normal GWT Composite widget does, but you can use GwtQuery to manipulate the DOM.

So for a template like:

Hello <span id="planet"></span>

You can put in your Template widget:

import static*;
public MyTemplate()}