My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
UiBinder  

Featured
Updated Aug 20, 2010 by joe...@gmail.com

#See how easy using the UiBinder is

Using a Page that references it's own template (non-MVP)

You can use a very simple convenience class: UiBoundPage. This, using deferred binding, will automatically inject the ui binder code so your page looks like this:

> FooPage.java

    public class MyPage extends UiBoundPage<FlowPanel> {

        @UiField
        TextBox myTextBox

	protected void onConstruct(FlowPanel widget) {
		// here is where you would reference ui fields
	}

	@Override
	public void onEnterPage(PageParameters parameters,
			PageRequestSession pageRequestData, AsyncPageCallback callback) {
            myTextBox.setText(...);
	}
    }

> FooPage.ui.xml

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
	xmlns:g='urn:import:com.google.gwt.user.client.ui'>
	<g:FlowPanel>
		<g:HTML>this is some other stuff in the page</g:HTML>
		<g:TextBox ui:field="myTextBox"/>
	</g:FlowPanel>
</ui:UiBinder>

That't it... you don't have to write that same old UiBinder code on every page...

Using a Page containing a view which references a template (MVP pattern)

It is almost as easy to have a presenter page that is injected with a widget that has a widget it can reference as a view.

> FooPresenterPage.java

public class FooPresenterPage extends PresenterPage {

	public interface FooDisplay {
		HasText getMyTextThingy();
	}
	
	@Override
	public void onEnterPage(PageParameters parameters,
			PageRequestSession session, AsyncPageCallback callback)
			throws Exception {
		FooDisplay display = (FooDisplay) getRawDisplay();
		display.getMyTextThingy().setText(...);
	}

}

> FooDisplayImpl

public class FooDisplayImpl extends UiBoundWidget<FlowPanel> implements
		FooPresenterPage.FooDisplay {

	@UiField
	TextBox myTextBox;

	@Override
	protected void onConstruct(FlowPanel widget) {
	}
	
	@Override
	public HasText getMyTextThingy() {
		return myTextBox;
	}

}

> FooDisplayImpl.ui.xml

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
	xmlns:g='urn:import:com.google.gwt.user.client.ui'>
	<g:FlowPanel>
		<g:HTML>this is some other stuff in the page</g:HTML>
		<g:TextBox ui:field="myTextBox"/>
	</g:FlowPanel>
</ui:UiBinder>

Now, all you need to do is to hook these together. This is done when registering the pages with the page loader. All of the page loaders have a similar API:

public class MyPageLoader extends StandardPageLoader {
    registerPages() {
        registerPage("fooPageToken", FooPresenterPage.class, FooDisplayImpl.class);
    }
}
}}
Powered by Google Project Hosting