css - GWT:如何在同一个 ClientBundle 的另一个样式表中访问一个样式表中定义的常量

标签 css gwt cssresource

这个问题最好用一个例子来描述。

我的 GWT 应用程序中有以下 ClientBundle:

interface Resources extends ClientBundle {
    public static final Resources INSTANCE = GWT.create(Resources.class);

    @Source("defines.css")
    Defines defines();

    @Source("appStyle.css")
    @CssResource.NotStrict
    Style style();

    interface Style extends CssResource {
        String appLogo();
        (...)
    }

    interface Defines extends CssResource {
        String formInputBackgroundColor();
        String formInputBorderColor();
        (...)
    }
}

appStyle.css是应用程序使用的主要样式表,defines.css是一个仅包含如下常量的样式表:

@def formInputBackgroundColor #D8ECFD;
@def formInputBorderColor #7FAAFF;
(...)

现在我可以使用 defines.css 中的常量了UIBinder 模板和应用程序代码中的样式表没有问题,但我不能在我的 appStyle.css 中使用这些常量.

我已经尝试替换 interface Style extends CssResourceinterface Style extends Defines , 希望继承自 Defines样式表将使我能够访问“子”Style 中的常量样式表,但随后 GWT 编译器会报错,例如:

Rebinding my.project.client.resources.Resources
    Creating assignment for style()
        Replacing CSS class names
            The following obfuscated style classes were missing from the source CSS file:
                formInputBorderColor: Fix by adding .formInputBorderColor{}
                formInputBackgroundColor: Fix by adding .formInputBackgroundColor{}
                (...)

有什么办法可以实现吗?

最佳答案

我找到了一种方法来做到这一点,但它远非优雅,我更喜欢另一种解决方案,比如尽可能使用某种继承或注释。

我让它工作的方法是 @eval appStyle.css 样式表中的 defines.css 我需要的每个常量,但这会导致大量代码重复,而且维护起来很麻烦。

@eval formInputBackgroundColor Resources.INSTANCE.defines().formInputBackgroundColor();
@eval formInputBorderColor Resources.INSTANCE.defines().formInputBorderColor();

如果您有更好的解决方案,请分享。

关于css - GWT:如何在同一个 ClientBundle 的另一个样式表中访问一个样式表中定义的常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3199880/

相关文章:

javascript - 如何在php中的header中设置目录

java - Vaadin项目编译和执行

css - GWT:为同一 CSS 字段返回多种样式

PHP 数据库 - 不想显示 javascript 代码

javascript - Font Awesome 图标不显示

java - 解析日期向格式化日期添加一天

html - 在 gwt 中使用 html 模板

gwt - 在 GWT 中需要应用范围的 CSS 常量

css - 如何覆盖现代 GWT 应用程序中的默认 CSS?

html - 下一行的 mPDF 和 bootstrap 列