3

I want to render in a template an image that originates from a ClientBundle. But what I get instead is this:

<img="#">

I've checked the contents of the datasource and if I copy the image (data:image/png;base64...) in {0} it works.

Why it doesn't work if I pass it as a parameter?

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);       
}
Jean-Michel Garcia
  • 2,359
  • 2
  • 23
  • 44
Spiff
  • 3,873
  • 4
  • 25
  • 50

1 Answers1

3

Use SafeUri as the argument type on your template, otherwise the value will be sanitized and a data: URI is considered unsafe.

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • SafeUri can't be used, i get an error, but the error suggests that I use SafeHtml, and that works. – Spiff Aug 31 '12 at 06:33
  • 1
    What's the error message with SafeUri? and which GWT version are you using? `com.google.gwt.user.client.ui.impl.ClippedImageImpl` uses `SafeUri` in `SafeHtmlTemplates` starting with GWT 2.4: http://code.google.com/p/google-web-toolkit/source/browse/tags/2.4.0/user/src/com/google/gwt/user/client/ui/impl/ClippedImageImpl.java – Thomas Broyer Aug 31 '12 at 09:38