我試圖使用一個圖像從ClientBundle
作爲UIBInder模板中的背景圖像。我使用this discussion作爲指南,但無法使其工作。使用ClientBundle圖像作爲背景圖像
在我的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>
工作,所以我試圖讓這項工作。但是,您似乎無法同時包含兩種CSS樣式(例如,我的paidIcon()
方法)和DataResources在<ui:data>
資源中。我無法找到關於<ui:data>
的很多文檔,所以我真的只是用這種方法來理解。
嗯試過了,但它有錯誤「ERROR:延遲綁定的結果類型‘com.example.client.PriceButton.Styles.PriceButtonStyles’不應該是抽象的。」在我的EntryPoint的頂部,我調用了GWT。 create(PriceButton.Styles.PriceButtonStyles.class).ensureInjected()。我在與Java代碼相同的包中有PriceButtonStyles.css。另外,我必須將上層界面重命名爲「樣式」,因爲它不喜歡具有相同名稱的嵌入式界面。 –
2011-03-18 17:15:43
對不起,給兩個接口同名。我認爲你的錯誤來自注入風格的呼叫。您需要將< >和() – 2011-03-18 17:27:41
之間的上一級界面添加到您的'ImageResource'方法中,以便確保圖像不被* sprited * in一些瀏覽器(即IE6/7) – 2011-03-21 23:28:51