Search code examples
cssgwtuibinder

gwt css uibinder sharing resource


I've defined a ClientBundle, a Style interface and hooked it up with my css file via the @source annotation.

I have two questions:

  1. when I use <ui:with> in my uibinder file I get the following exception: Deferred binding result type MyStyle should not be abstract. Can someone explain what's going on? And how I can include the style correctly in my uibinder file?

  2. I'd like to share the resource across many uibinder without paying the penalty of initializing the style every time. Gwt's anemic dev guide, suggests using the UiField(provided=true) or using a @uiFactory. Although I've successfully used @uiFactory in order to use my own custom widgets. I have no idea how to use a @uiFactory to inject a style into the uiBinder.

For example:

//in pojo
@UiFactory
public MyStyle getMyStyle() {
    return myStyle;
}

//in uibinder
<g:Label addStyleNames="{myStyle.defaultLable}"/>

how can i get this work?

Thanks in advance.


Solution

  • I use the following construction in the uibinder file:

    <ui:with field='res' type="com.example.client.resources.MyResource" />
    

    Where MyResource is an interface containing the css resource:

    public interface MyResource extends ClientBundle {
      @Source("mycss.css")
      MyCssResource css();
    }
    

    and MyCssResource is:

    public interface MyCssResource extends CssResource {
        String someStyle();
    }
    

    In uibinder file this is used as follows:

    <g:TextBox addStyleNames="{res.css.someStyle}" />