Joey
Joey

Reputation: 2792

GWT - CellTable/DataGrid Using ImageCell

I want to add an ImageCell in a CellTable. my code is the following:

Column<Message, String> myColumn = new Column<Message, String>(new ImageCell()) {
    @Override
    public String getValue(Message details) {
        Image image =  new Image (ClientResources.of().image1());
        return image.getUrl();      
    }
};

It shows the following warnning when I run it:

[WARN] [adminportal] - Template with variable in URL attribute context: The template code generator cannot guarantee HTML-safety of the template -- please inspect manually or use SafeUri to specify arguments in a URL attribute context

My question is that how I can return the url as string value safely. I saw an example about using imagecell before and the return value is string. I cannot find it now. Could anyone tell me how to fix this.

Note: I just want to know how to fix this if I want to use imagecell in celltable and return value is string. I know how to use imageresourcecell to achieve the same goal. Also, I know I can change the type of getValue() from string to safeHtml to achieve the goal. But i am really wondering how to achieve this by using imagecell and string type of getValue() because I saw an example about this before and I tried it successfully. Just cannot remember what I did wrong here.

Upvotes: 2

Views: 1784

Answers (1)

Thomas Broyer
Thomas Broyer

Reputation: 64541

There's no way to fix this (remove the warning): using a String as part of a template is inherently unsafe, and GWT warns you about it. If you're absolutely certain of the safety of your values, then you can safely ignore the warnings, but they'll still be emitted.

The only way to not have those warnings is to use a SafeUri, i.e. use the SafeImagecell. It's then up to you to guarantee the safety of your URL, depending on the method you use to construct the SafeUri (have a look at UriUtils)

Upvotes: 2

Related Questions