gwt - 外部ClientBundle中ImageResource的@url,在UiBinder中使用

标签 gwt uibinder

ImageResourceUiBinder 时,是否可以在 UiBinder 中使用 @url 引用 ImageResource 不在同一个包中

例如:

我共享的ClientBundle:

package com.myproject.client.resources;

class SharedResources extends ClientBundle {
    ImageResource myImage();
}

以及 com.myproject.client 包中的 UiBinder 文件。另一个包

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
             xmlns:g='urn:import:com.google.gwt.user.client.ui'>
    <ui:with field="res" type="com.myproject.client.resources.SharedResources"/>
    <ui:style>
        @url myImg {insert reference to res.myImage}

        .theClass {
            background: myImg no-repeat center center #d7d6d6;
            width: 21px;
        }
    </ui:style>
    <g:HTMLPanel styleName="{style.theClass}"/>
</ui:UiBinder>

我知道我可以将 CSS 移动到 com.myproject.client.resources,然后我就可以轻松访问 myImage (因为 CSS 和 myImage 将位于同一个包中),但我更愿意将 CSS 保留在 UiBinder 内,并在 UiBinder 中重用共享的 myImage

这里有一个关于这个问题的讨论,但它没有回答我的问题: https://groups.google.com/forum/#!topic/google-web-toolkit/ExOJAEfQmkY

最佳答案

我遇到了同样的问题,我的解决方案是使用ui:image。此解决方案不会像我认为您想要的那样重用并直接引用 ClientBundle,但它使您可以不移动 CSS,或将图像复制到文件夹,或创建新的 ClientBundle。

代码类似于:

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
             xmlns:g='urn:import:com.google.gwt.user.client.ui'>
    <ui:with field="res" type="com.myproject.client.resources.SharedResources"/>
    <ui:image field="resImage" src="../resources/image.png" />
    <ui:style>
        @url myImg resImage

        .theClass {
            background: myImg no-repeat center center #d7d6d6;
            width: 21px;
        }
    </ui:style>
    <g:HTMLPanel styleName="{style.theClass}"/>
</ui:UiBinder>

我保留了 SharedResources 引用只是为了说明如何使用您的示例,但在本例中并未使用它。

关于gwt - 外部ClientBundle中ImageResource的@url,在UiBinder中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22211273/

相关文章:

gwt - 如何在 UiBinder 中为 GWT 小部件设置 id?

java - 使用 CSS 清理我的 customLabel

css - 以 GWT UiBinder 样式访问 CSS 常量

java - 在 GWT 中使用 UiBinder 将 Ui 绑定(bind)到 java 接口(interface)

GWT 设计器滞后于 xml 源自动完成

java - 使用 GWT 和 Maven 得到 UnsupportedActionException

java - 如何删除屏幕上的 GWT 菜单栏单击?

java - 本地tomcat中的GWT应用: nocache. js 404未找到

java - GXT-3 问题为我的图表加载数据

java - GWT 异步回调上的 Hashmap 为空