【发布时间】:2011-07-18 06:46:18
【问题描述】:
我正在尝试使用来自ClientBundle 的图像作为 UIBInder 模板中的背景图像。我使用this discussion 作为指导,但无法让它工作。
在我的 Java 类中,我有:
public static interface PriceButtonStyles extends ClientBundle
{
String paidIcon();
@ClientBundle.Source("paid_button_53x31.png")
DataResource paid_buttonAsDataResource();
}
@UiField
PriceButtonStyles priceButtonStyle;
然后在相应的模板文件中我像这样引用它:
<ui:style field="priceButtonStyle" type="com.example.client.PriceButton.PriceButtonStyles">
@url paidIconUrl paid_buttonAsDataResource;
.paidIcon {
background: paidIconUrl 0 0 no-repeat;
}
</ui:style>
此时我的 IDE 已经将“paidIconUrl”字符串显示为红色,表明有些地方不太正确:
确实,当我尝试运行它时,我得到:
ERROR: Type com.ecample.client.PriceButton.PriceButtonStyles does not extend com.google.gwt.resources.client.CssResource Element <ui:style field='priceButtonStyle' type='com.example.client.PriceButton.PriceButtonStyles'> (:7).
ERROR: Uncaught exception escaped. com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses
进一步在Google Groups discussion 中建议这可能与<ui:data> 而不是<ui:style> 一起工作,所以我试图让它工作。但似乎您不能在 <ui:data> 资源中同时包含 CSS 样式(例如我的 paidIcon() 方法)和 DataResources。我无法在 <ui:data> 上找到太多文档,所以我真的只是抓住了这根稻草。
【问题讨论】: