Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT - problems with constants in css

Tags:

css

constants

gwt

I'm new to GWT; I'm building a small sample app. I have several CSS files. I'm able to successfully use the ClientBundle and CssResource to assign styles to the elements defined in my UiBinder script.

Now I'd like to take it one step further and introduce CSS constants using @def css-rule. The @def works great when I define a constant and use it in the same CSS file. However I cannot use it in another CSS file. When I try to use the @eval rule to evaluate an existing constant the compiler throws an execption: "cannot make a static reference to the non-static method ".

Here is an example of what I'm trying to do:

ConstantStyle.css

@def BACKGROUND red;

ConstantStyle.java

package abc;
import ...;
interface ConstantStyle extends cssResource {
         String BACKGROUND();
}

MyStyle.css

@eval BACKGROUND abc.ConstantStyle.BACKGROUND();
.myClass {background-color: BACKGROUND;}

MyStyle.java

package abc;
import ...;
interface ConstantStyle extends cssResource {
         String myClass;
}

MyResources.java

package abc;
import ...;
interface MyResources extends ClientBundle {
    @Source("ConstantStyle.css")
     ConstantStyle constantStyle();

    @Source("MyStyle.css")
    MyStyle myStyle();
}

Thanks in advance!

like image 450
hba Avatar asked Aug 14 '26 18:08

hba


1 Answers

Add "ConstantStyle.css" to the @Source annotation in ClientBundle like this:

package abc;
import ...;
interface MyResources extends ClientBundle {
    @Source("ConstantStyle.css")
     ConstantStyle constantStyle();

    @Source({"ConstantStyle.css", "MyStyle.css"})
    MyStyle myStyle();
}

It does the same as would @import "ConstantStyle.css" in MyStyle.css (except @import is ignored by GWT I believe).

You don't need @eval.

like image 87
alshan Avatar answered Aug 16 '26 13:08

alshan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!