How can I use CssResources in UiBinder a generated Cell?

Posted by confile on Stack Overflow See other posts from Stack Overflow or by confile
Published on 2014-06-08T15:21:13Z Indexed on 2014/06/08 15:24 UTC
Read the original article Hit count: 184

Filed under:
|
|
|
|

I want to generate a Cell for a CellWidget with the UiBinder (UiRenderer). What I did to generate the cell is in MyCell.java:

public class MyCell implements AbstractCell<MyDto> {

    public interface Resources extends ClientBundle {

        @Source({Css.DEFAULT_CSS })
        Css css();
    }

    public interface Css extends CssResource {

        String DEFAULT_CSS = "test/MyStyle.css";
        String test();
    }

    interface MyUiRenderer extends UiRenderer {
        void render(SafeHtmlBuilder sb, String name, SafeStyles styles);
    }

    private static MyUiRenderer renderer = GWT.create(MyUiRenderer.class);

    Resources resources = GWT.create(Resources.class);

    @Override
    public void render(SafeHtmlBuilder safeHtmlBuilder, MyDto model) {

        SafeStyles style = SafeStylesUtils.fromTrustedString(resources.css().test().toString());
        renderer.render(safeHtmlBuilder, model.getName(), style);

    }

}

My MyCell.ui.xml file looks like this:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'>

    <ui:with field="name" type="java.lang.String" />
    <ui:with field='styles' type='com.google.gwt.safecss.shared.SafeStyles'/> 


    <div style="{styles}"><ui:text from="{name}" /></div>


</ui:UiBinder>

MyStyle.css:

.test {
  background-color: red;
  font-size: 20px;
  display: flex;
  ...
}

When I run my code I get the following error:

[DEBUG] [mobile] - Rebinding test.client.app.MyCell.MyUiRenderer
    [DEBUG] [mobile] - Invoking generator com.google.gwt.uibinder.rebind.UiBinderGenerator
        [ERROR] [mobile] - java.lang.String required, but {styles} returns com.google.gwt.safecss.shared.SafeStyles: <div style='{styles}'> (:9)
[ERROR] [mobile] - Deferred binding failed for 'test.client.app.MyCell.MyUiRenderer'; expect subsequent failures
[ERROR] [mobile] - (GWT.java:72) 2014-06-08 17:15:05,214 [FATAL] Uncaught Exception:

Then I tried to this:

in my UiBinder but it does not work.

How can I use css style from a CssResource in my UiRenderer?

© Stack Overflow or respective owner

Related posts about java

Related posts about JavaScript