[英]Do I really need to put css resource file into a ClientBundle in GWT?
[英]GWT - ClientBundle for CSS file not working with class names
我有一個GWT問題,
我試圖將css作為CssResource移到ClientBundle,因為它聲稱是最佳實踐,但是存在問題。 它確實適用於element-ID和element-name,但不適用於類名。 所以當我有
div{
color: red;
}
#whatever_id{
color: black;
}
但是如果我添加一個帶點(。)的類名
div{
color: red;
}
#whatever_id{
color: black;
}
.whatever_classname{
color: green;
}
然后我開始興奮
onModuleLoad() threw an exception
Exception while loading module com.acatime.edutime.client.edutime. See Development Mode for details.
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:411)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:526)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.ExceptionInInitializerError
at com.acatime.edutime.client.edutime.onModuleLoad(edutime.java:29)
... 9 more
Caused by: java.lang.RuntimeException: Deferred binding failed for 'com.acatime.edutime.client.resources.GeneralResources' (did you forget to inherit a required module?)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:53)
at com.google.gwt.core.shared.GWT.create(GWT.java:72)
at com.google.gwt.core.client.GWT.create(GWT.java:86)
at com.acatime.edutime.client.resources.GeneralResources.<clinit>(GeneralResources.java:11)
... 10 more
Caused by: com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
at com.google.gwt.dev.shell.ModuleSpace.rebind(ModuleSpace.java:610)
at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:470)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
... 13 more
知道我缺少什么嗎???
包含下划線的類名稱曾經存在問題。 嘗試不帶下划線的類名。
謝謝Andrei和Braj的回答。 我發現了我所缺少的。
從一開始我沒有得到的是,我正在添加類名,如下所示:
myWidget.setStyleName("whateverClassname);
顯然這就是問題所在。 看起來,當您通過ClientBundle / CssResource使用CSS時,必須指定類名稱,如下所示:
myWidget.setStyleName(MyResources.INSTANCE.myCss()whateverClassname());
而且,突然之間,一切正常,:)我希望現在這是向GWT應用程序添加樣式的正確方法。 我是GWT的新手,並嘗試遵循GWT網站上推薦的最佳做法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.