SafeHtml and SafeStyles

999 views
Skip to first unread message

Deyan Atanasov

unread,
May 4, 2011, 12:39:36 PM5/4/11
to Google Web Toolkit
Hi, I am trying to implement SafeHtml with some parameters in the HTML
style atribute:
Example:

@Template("<div style=\"{0}\"><div style=
\"position:absolute;display:none;"
+ "\"></div><div>{1}</div></div>")
SafeHtml unsorted(SafeCSSWidth imageWidth, String text);

My SafeCSSWidth class implements SafeStyles, according to the contract
but the GWT compiler still outputs:
[INFO] Generating method body for unsorted()
[INFO] [WARN] Template with variable in CSS
attribute context: The template code generator cannot guarantee HTML-
safety of the template -- please inspect manually or use SafeStyle
s to specify arguments in a CSS attribute context
[INFO] Compiling 1 permutation
[INFO] Compiling permutation 0...

I am using GWT 2.3.0.
Any suggestions ?

Thomas Broyer

unread,
May 4, 2011, 12:55:55 PM5/4/11
to google-we...@googlegroups.com
Have a look at the SafeStylesUtils and SafeStylesBuilder; and change your "imageWidth" argument to SafeStyles (where's that SafeCSSWidth coming from?!)

Joseph Lust

unread,
May 2, 2012, 12:14:35 PM5/2/12
to google-we...@googlegroups.com
@Template("<div style=\"{0}\"><div style=\"position:absolute;display:none;"\></div><div>{1}</div></div>")
SafeHtml unsorted(SafeStyles imageWidthStyle, SafeHtml text); 

double width = 34.34d;
SafeStyles imageWidthStyle = SafeStylesUtils.fromTrustedString("width:"+width+"px;");
SafeHtml text = SafeHtmlUtils.fromString("blah");
unsorted( imageWidthStyle, text ); // call your template

That is how I'd do it. I had to fix some warnings to this end this morning for some code, so I had to look this usage up. Hope it helps.


Sincerely,
Joseph

Thomas Broyer

unread,
May 2, 2012, 12:24:54 PM5/2/12
to google-we...@googlegroups.com
And when GWT 2.5 will be out the door:
SafeStyles imageWidthStyle = SafeStylesUtils.forWidth(width, Unit.PX);

Joseph Lust

unread,
May 2, 2012, 12:46:23 PM5/2/12
to google-we...@googlegroups.com
I look forward to it since writing string literals for CSS properties seems silly in this day and age.

Joe
Reply all
Reply to author
Forward
0 new messages