当 ImageResource
和 UiBinder
时,是否可以在 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/