Thursday, July 29, 2010 22:32

GWT Exception – The style name should be in camelCase

Tagged with:
Posted by ukoom on Saturday, December 12, 2009, 14:49
This news item was posted in Java category and has 0 Comments so far.

When I needed to add or modify a CSS property of an element in Google Web Toolkit (GWT), I’d always do it like this :

widget.getElement().setAttribute("style", "align:right;");

However, if there was already any style information for defined for that element, it would be overwritten. You could get the current attributes first and then readd them along with your new info but there is a much cleaner way :

widget.getElement().getStyle().setProperty("align", "right");

Important! Note that when setting a style property, your need to use camel case for the property name.

//WRONG!
myWidget.getElement().getStyle().setProperty("background-color", "red");
// RIGHT
myWidget.getElement().getStyle().setProperty("backgroundColor", "red");

This solution is from http://www.francoismaillet.com/blog/?p=68

Related Posts

Leave a Reply

You can leave a response, or trackback from your own site.