Attaching ImageResource from an External CSS File Using @sprite

I am trying to use CssResource and ImageResource together in a GWT2.2 project.

CssResource and obfuscation work fine, but I have problems accessing images.

I can already access images through ImageResource directly from the ui.xml files as follows:

<ui:with type="com.example.client.resource.ResourceBundle" field="myResource"/> <g:Image resource="{myResource.image}"/> 

But I can not connect ImageResource from external .css files using @sprite.

I have the following interfaces:

 public interface ResourceBundle extends ClientBundle { ResourceBundle INSTANCE = GWT.create (ResourceBundle.class); @Source("com/example/client/resource/images/image.png") ImageResource image(); @Source("com/example/client/resource/css/mystyle.css") MyCssResource myCssResource(); } public interface MyCssResource extends CssResource { String className(); } 

And when I add a sprite to the css file,

 @sprite .className { gwt-image: 'image'; } 

The following error message appeared:

 [ERROR] - Unable to find ImageResource method value("image") in com.example.client.views.MyView_BinderImpl_GenBundle : Could not find no-arg method named image in type com.example.views.MyView_BinderImpl_GenBundle 
+4
source share
1 answer

You can access your styles from UiBinder templates as follows:

 <ui:with type="com.example.client.resource.ResourceBundle" field="myResource"/> <g:FlowPanel styleName="{myResource.myCssResource.className}"/> 
+2
source

Source: https://habr.com/ru/post/1346653/


All Articles