English 中文(简体)
GWT 2 CssResource how to
原标题:
  • 时间:2009-11-09 15:13:12
  •  标签:
  • gwt

I have a GWT 1.7 application and I want to upgrade it to GWT 2 Milestone 2. The application uses 2 big external CSS files. In GWT 1.7 I had a public folder and put both the CSS files in the folder and my application compiled and worked fine. Now for GWT 2 I have created a ResourceBundle class and put all image sprites and CSS as follows:

public interface ResourceBundle extends ClientBundle {

 public static final ResourceBundle INSTANCE = GWT.create(ResourceBundle.class);

 @Source("com/web/tech/public/stylesheet1.css")
 public Css stylesheet1();

 @Source("com/web/tech/public/stylesheet2.css")
 public Css stylesheet2();

 @Source("com/docobo/keswick/keswickweb/public/images/organisnew.gif")
 public ImageResource add_org();

.....
}

The Css class is an empty class extending CssResource :

public interface Css extends CssResource{

}

Then in my onModuleLoad() I use :

StyleInjector.inject(ResourceBundle.INSTANCE.stylesheet1().getText());
StyleInjector.inject(ResourceBundle.INSTANCE.stylesheet2().getText());

When I compile I get the following error:

     Rebinding com.docobo.keswick.keswickweb.client.ClientResources.ResourceBundle
            Invoking <generate-with class= com.google.gwt.resources.rebind.context.InlineClientBundleGenerator />
               Creating assignment for gxt_gray()
                  Replacing CSS class names
                     [ERROR] The following unobfuscated classes were present in a strict CssResource:
                        [ERROR] x-tab-scroller-left
                        [ERROR] x-tab-strip-disabled
                        [ERROR] ......loads of other styles

Fix by adding String accessor method(s) to the CssResource interface for obfuscated classes, or using an @external declaration for unobfuscated classes.

Following the above instruction when I use @external above all my style classes inside the CSS file I get the following error :

 [ERROR] Generator  com.google.gwt.resources.rebind.context.InlineClientBundleGenerator  threw threw an exception while rebinding  com.docobo.keswick.keswickweb.client.ClientResources.ResourceBundle 
java.lang.StringIndexOutOfBoundsException: String index out of range: -2
 at java.lang.String.substring(Unknown Source)
 at com.google.gwt.resources.css.GenerateCssAst$GenerationHandler.ignorableAtRule(GenerateCssAst.java:236)
 at org.w3c.flute.parser.Parser.atRuleDeclaration(Parser.java:1178)
 at org.w3c.flute.parser.Parser.ignoreStatement(Parser.java:622)
 at org.w3c.flute.parser.Parser.parserUnit(Parser.java:452)
 at org.w3c.flute.parser.Parser.parseStyleSheet(Parser.java:107)
 at org.w3c.flute.parser.Parser.parseStyleSheet(Parser.java:119)
 at com.google.gwt.resources.css.GenerateCssAst.exec(GenerateCssAst.java:663)
 at com.google.gwt.resources.rg.CssResourceGenerator.prepare(CssResourceGenerator.java:506)
 at com.google.gwt.resources.rebind.context.AbstractClientBundleGenerator.initAndPrepare(AbstractClientBundleGenerator.java:531)
 at com.google.gwt.resources.rebind.context.AbstractClientBundleGenerator.initAndPrepare(AbstractClientBundleGenerator.java:502)
 at com.google.gwt.resources.rebind.context.AbstractClientBundleGenerator.generate(AbstractClientBundleGenerator.java:179)
 at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:49)
 at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.tryRebind(StandardRebindOracle.java:108)
 at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:54)
 at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:154)
 at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:143)
 at com.google.gwt.dev.Precompile$DistillerRebindPermutationOracle.getAllPossibleRebindAnswers(Precompile.java:315)
 at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.doFindAdditionalTypesUsingRebinds(WebModeCompilerFrontEnd.java:107)
 at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.process(AbstractCompiler.java:161)
 at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:444)
 at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.compile(AbstractCompiler.java:84)
 at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.compile(AbstractCompiler.java:196)
 at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.access$300(AbstractCompiler.java:70)
 at com.google.gwt.dev.jdt.AbstractCompiler.compile(AbstractCompiler.java:481)
 at com.google.gwt.dev.jdt.BasicWebModeCompiler.getCompilationUnitDeclarations(BasicWebModeCompiler.java:113)
 at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.getCompilationUnitDeclarations(WebModeCompilerFrontEnd.java:49)
 at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.precompile(JavaToJavaScriptCompiler.java:415)
 at com.google.gwt.dev.jjs.JavaScriptCompiler.precompile(JavaScriptCompiler.java:32)
 at com.google.gwt.dev.Precompile.precompile(Precompile.java:507)
 at com.google.gwt.dev.Precompile.precompile(Precompile.java:408)
 at com.google.gwt.dev.Compiler.run(Compiler.java:194)
 at com.google.gwt.dev.Compiler$1.run(Compiler.java:145)
 at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:89)
 at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:83)
 at com.google.gwt.dev.Compiler.main(Compiler.java:152)  
问题回答

Try with @NotStrict. Example:

@NotStrict
@Source("com/web/tech/public/stylesheet1.css")
public Css stylesheet1();

Got it solved. As pointed out by Thomas@Google Groups --> The @external must not be put "above" the style

http://code.google.com/p/google-web-toolkit/wiki/CssResource#External...

The example from this link, the css will look like :

@external .legacySelectorA, .legacySelectorB;
.obfuscated .legacySelectorA { .... }
.obfuscated .legacySelectorB { .... }

/* @external also accepts tail-globs */
@external .myProject-*;
.myProject-text {}
.myProject-foo {}




相关问题
Refresh the UI in gwt

I have created some custom composite widget, which listens to an events (in my case loginEvent). Once the event is caught the state of the widget changes so as the way it should look (in my case I ...

How to create a development/debug and production setup

I recently deployed inadvertently a debug version of our game typrX (typing races at www.typrx.com - try it it s fun). It was quickly corrected but I know it may happen again. After digging on ...

GWT error at runtime: ....style_0 is null

My code works fine in IE 8, but on firefox 3.5, the javascript fails to load. I used firebug to figure out why, and the error I get is (GWT detailed mode) My suspicion is that some style is not ...

GWT s hosted mode not working

I ve been stumped for a while trying to figure out why my GWT demo app isn t working in hosted mode so I went back and downloaded the Google Web Toolkit again, unzipped it and simply went to the ...

How to disable Google Visualizations Tool Tips?

Does anyone know how to disable the tool-tip boxes that popup when a Google Visualizations chart is clicked (Selected)? Following the sample code at Getting Started with Visualizations, the "...

GWT 2 CssResource how to

I have a GWT 1.7 application and I want to upgrade it to GWT 2 Milestone 2. The application uses 2 big external CSS files. In GWT 1.7 I had a public folder and put both the CSS files in the folder and ...

热门标签