在遇到一些不推荐的将css资源包含到应用程序中的方法的问题后,我渴望使用ClientBundle来包含css文件。
我在###.gwt.xml文件中添加了以下行:
<inherits name="com.google.gwt.resources.Resources" />
我创建了一个界面,看起来像这样:
import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
public interface ResourceBundle extends ClientBundle
{
public static final ResourceBundle INSTANCE = GWT.create(ResourceBundle.class);
@Source("GWT_Chat.css")
public CssResource css();
}
在我的onModuleLoad()方法中,我正在调用:
Window.alert(ResourceBundle.INSTANCE.css().getText());
我的css文件是一个随机的css文件,没有任何可能的gwt添加。
当在浏览器中调用应用程序时,我面临的错误是:
[ERROR] [gwt_chat] - Line 33: No source code is available for type de.main.resources.ResourceBundle;
did you forget to inherit a required module?
我遗漏了什么吗?
是的,您需要实现CssResource
的子类型并返回它:
public interface ResourceBundle extends ClientBundle
{
public static final ResourceBundle INSTANCE = GWT.create(ResourceBundle.class);
@Source("GWT_Chat.css")
public MyCssResource css();
public static interface MyCssResource extends CssResource {
String getText();
}
}