2012-08-30 19 views
3

我想在模板中呈現源自ClientBundle的圖像。 但我得到的卻是這樣的:從模板中的數據源呈現圖像

<img="#"> 

我已經檢查了數據源的內容,如果我複製圖像(數據:圖像/ PNG; BASE64 ...)在{0}它的工作原理。

如果我將它作爲參數傳遞,爲什麼它不起作用?

DataResource inputCheckImage = MGWTStyle.getTheme().getMGWTClientBundle().inputCheckImage(); 
private static Template TEMLPATE = GWT.create(Template.class); 

public interface Template extends SafeHtmlTemplates 
{ 
    @SafeHtmlTemplates.Template("<div><img src=\"{0}\"></div>") 
    SafeHtml content(String image); 
} 

//@Override 
public void render(SafeHtmlBuilder safeHtmlBuilder, Action model) { 

    SafeUri url = inputCheckImage.getSafeUri(); 
    SafeHtml safeHtml = TEMLPATE.content(url.asString()); 
    safeHtmlBuilder.append(safeHtml);  
} 

回答

3

使用SafeUri作爲模板參數類型,否則值將被消毒和數據:URI被認爲是不安全的。

+0

SafeUri無法使用,我得到一個錯誤,但錯誤表明我使用SafeHtml,並且工作。 – Spiff

+1

SafeUri的錯誤信息是什麼?以及您使用的是哪個GWT版本? 'com.google.gwt.user.client.ui.impl.ClippedImageImpl'從GWT 2.4開始使用'SafeHtmlTemplates'中的'SafeUri':http://code.google.com/p/google-web-toolkit/source/瀏覽/ tags/2.4.0/user/src/com/google/gwt/user/client/ui/impl/ClippedImageImpl.java –

+0

是的,你說得對,謝謝。 – Spiff