java - How can I use CssResources in UiBinder a generated Cell? -
i want generate cell cellwidget uibinder (uirenderer). did generate cell 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 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 run code 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, {styles} returns com.google.gwt.safecss.shared.safestyles: <div style='{styles}'> (:9) [error] [mobile] - deferred binding failed 'test.client.app.mycell.myuirenderer'; expect subsequent failures [error] [mobile] - (gwt.java:72) 2014-06-08 17:15:05,214 [fatal] uncaught exception:
then tried this:
<ui:with field="styles" type="java.lang.string" />
in uibinder not work.
how can use css style cssresource in uirenderer?
<div style="{styles}">
two problems here. first, in order change style of element, have 2 options, setting style attribute include specific properties, or set class attribute point class you’ve defined in css somewhere. so, want set class
here, not style
.
second, created css class called "test", assigning here whole interface, styles. instead, reference styles.test:
<div class="{styles.test}" />
edit: 1 final piece may missing (but since "this not work" vague don't know if actual problem): don't see call ensureinjected()
in example. make sure call on css
instance before using it.
Comments
Post a Comment