Re: How to avoid "CSS attribute context" warning with GWT 2.5's UiRenderer?

725 views
Skip to first unread message

Ignacio Baca Moreno-Torres

unread,
Mar 4, 2013, 2:58:15 AM3/4/13
to google-we...@googlegroups.com
Have you tried this?
<ui:with field='styles' type='com.google.gwt.safecss.shared.SafeStyles'/>
Also you can add a one resource class and just specify the return type correctly in the class (see http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/test/com/google/gwt/uibinder/test/client/UiRendererUi.ui.xml?r=10548).

On Mar 4, 2013, at 2:59 AM, Enrique Rodriguez <enri...@gmail.com> wrote:

I'm trying to port a GWT 2.4 AbstractCell that uses SafeHtmlTemplates to a GWT 2.5 AbstractCell that uses UiRenderer.  My problem is that when I set the CSS style directly on a div element, GWT logs the "CSS attribute context" warning in my logs.  Using a String, the Cell works fine albeit with the warning, but my attempts to pass a SafeStyles have failed.

In my GWT 2.4 AbstractCell I had a template that used SafeStyles:

@SafeHtmlTemplates.Template("<div style=\"{0}\">{1}</div>")
      SafeHtml cell(SafeStyles styles, SafeHtml value);

When I try passing a SafeStyles, I get the following error:

17:18:33.582 [ERROR] [my.widgets] java.lang.String required, but {styles} returns com.google.gwt.safecss.shared.SafeStyles: &lt;div  style='{styles}'&gt; (:28)

When I use a String, everything works correctly, however I get the expected "CSS attribute context" warning.

17:16:51.108 [WARN] [my.widgets] Template with variable in CSS attribute context: The template code generator cannot guarantee HTML-safety of the template -- please inspect manually or use SafeStyles to specify arguments in a CSS attribute context

Incidentally, I had a similar issue passing an image URL.  The logs warned me to use SafeUri, which I did and it worked, so it appears that img recognizes a SafeUri but div won't recognize a SafeStyles.

        <div style="{styles}">
            <img alt="{name}" src="{image}" />
        </div>

Enrique


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Enrique Rodriguez

unread,
Mar 4, 2013, 3:10:48 AM3/4/13
to google-we...@googlegroups.com
Your <ui:with> statement is exactly what I tried that gives the error.  To summarize, using type='java.lang.String' gives the warning to use SafeStyles and using type='com.google.gwt.safecss.shared.SafeStyles' gives the error to use a String.

The change log you referenced (r10548) is "... to make SafeUri work as expected." and further states "Similar will be needed for SafeStyles." which makes me think this is intended but not yet supported behavior.

Enrique

Ignacio Baca Moreno-Torres

unread,
Mar 4, 2013, 4:35:11 AM3/4/13
to google-we...@googlegroups.com
But did you transform the string to a safeStyle using SafeStyleUtils?

I test this with no warnings…
interface Template extends SafeHtmlTemplates {
    @Template("<span style=\"{0}\">...</span>")
    SafeHtml span(SafeStyles value);
}
RootPanel.get().add(new HTML(template.span(SafeStylesUtils.fromTrustedString("background: red;"))));

Thomas Broyer

unread,
Mar 4, 2013, 5:40:35 AM3/4/13
to google-we...@googlegroups.com


On Monday, March 4, 2013 10:35:11 AM UTC+1, Ignacio Baca Moreno-Torres wrote:
But did you transform the string to a safeStyle using SafeStyleUtils?

I test this with no warnings…
interface Template extends SafeHtmlTemplates {
    @Template("<span style=\"{0}\">...</span>")
    SafeHtml span(SafeStyles value);
}
RootPanel.get().add(new HTML(template.span(SafeStylesUtils.fromTrustedString("background: red;"))));

The issue is with UiBinder; SafeStyles obviously work OK with SafeHtmlTemplates (they're almost useless without it).
The problem is that UiBinder requires a String value for all HTML attributes, and then it generates a SafeHtmlTemplates, and the HTML parser used by the SafeHtmlTemplate generator knows which attribute accepts URLs or CSS, and warns if their values are not SafeUri or SafeStyles respectively.
So, UiBinder forces you to use a String, and generates a SafeHtmlTemplates that warns you that you don't use a SafeStyles.

@Enrique: please file an issue: UiBinder should at least accept SafeStyles in attributes, and then let the generated SafeHtmlTemplate warn or fail if used in inappropriate places.
Actually, this is already done for SafeUri in GWT 2.5, and needs to be done for SafeStyles (see https://code.google.com/p/google-web-toolkit/source/detail?r=10548 which explicitly says "Similar will be needed for SafeStyles.")

Przemysław Chmielewski

unread,
Nov 7, 2013, 6:47:51 AM11/7/13
to google-we...@googlegroups.com
W dniu poniedziałek, 4 marca 2013 11:40:35 UTC+1 użytkownik Thomas Broyer napisał:
The issue is with UiBinder; SafeStyles obviously work OK with SafeHtmlTemplates (they're almost useless without it).
The problem is that UiBinder requires a String value for all HTML attributes, and then it generates a SafeHtmlTemplates, and the HTML parser used by the SafeHtmlTemplate generator knows which attribute accepts URLs or CSS, and warns if their values are not SafeUri or SafeStyles respectively.
So, UiBinder forces you to use a String, and generates a SafeHtmlTemplates that warns you that you don't use a SafeStyles.

@Enrique: please file an issue: UiBinder should at least accept SafeStyles in attributes, and then let the generated SafeHtmlTemplate warn or fail if used in inappropriate places.
Actually, this is already done for SafeUri in GWT 2.5, and needs to be done for SafeStyles (see https://code.google.com/p/google-web-toolkit/source/detail?r=10548 which explicitly says "Similar will be needed for SafeStyles.")

Hello,

I have just same problem with using SafeStyle with UiRenderer for my cell.

Do you know when support SafeStyles in uibinder for HTML tag is expected?

I would appreciate any info about this issue.

Reply all
Reply to author
Forward
0 new messages