ClientBundle not able to set background image

725 views
Skip to first unread message

Deepak Singh

unread,
Nov 22, 2011, 1:37:35 PM11/22/11
to google-we...@googlegroups.com
Hi,

GWT 2.4

html contains one div as written below

<div id="topbar" style="background-image:url(images/top-bar-2.png);background-repeat: repeat-y;"></div>

Now i need to replace this image through clientbundle. So MyClientBundle as follows

@source("images/top-bar-2.png")
ImageSource topbar2();


i change my html like this
<div id="topbar" style="background-repeat: repeat-y;"></div>

and in java code i set
Document.get().getElementById("topbar").getStyle().setBackgroundImage(clientbundle.topbar2());

But it does not display image.

Somone pls identify my mistake.

Thanks
Deepak


--
Deepak Singh

darkflame

unread,
Nov 22, 2011, 2:04:28 PM11/22/11
to Google Web Toolkit
ImageSource?
Isnt it supposed to be ImageResource?


On Nov 22, 7:37 pm, Deepak Singh <deepaksingh...@gmail.com> wrote:
> Hi,
>
> GWT 2.4
>
> html contains one div as written below
>
> <div id="topbar"
> style="background-image:url(images/top-bar-2.png);background-repeat:
> repeat-y;"></div>
>
> Now i need to replace this image through clientbundle. So MyClientBundle as
> follows
>
> @source("images/top-bar-2.png")
> ImageSource topbar2();
>
> i change my html like this
> <div id="topbar" style="background-repeat: repeat-y;"></div>
>
> and in java code i set

> Document.get().getElementById("topbar").getStyle().setBackgroundImage(clien­tbundle.topbar2());

Deepak Singh

unread,
Nov 22, 2011, 2:08:46 PM11/22/11
to google-we...@googlegroups.com
Sorry.Writing mistake.
It is ImageResource only.

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




--
Deepak Singh

Andrea Boscolo

unread,
Nov 22, 2011, 2:14:17 PM11/22/11
to google-we...@googlegroups.com
Should be ImageResource yes, and I also think the setBackgroundImage(...) method accepts a String, not an ImageResource.

In the 2.4 release you should use

...setBackgroundImage(clientbundle.topbar2().getSafeUri().asString());

cause in 2.4 the getUrl() in the ImageResource is deprecated.

Deepak Singh

unread,
Nov 22, 2011, 2:25:11 PM11/22/11
to google-we...@googlegroups.com, gwtquery
Tried this also. But still image is not displayed.

If i use GQuery and does this one

$("#topbar").css(CSS.BACKGROUND_IMAGE.with(UriValue.url(HomePageClientBundle.INSTANCE.topbar2().getSafeUri().asString())));

then image gets displayed.

But using gwt

Document.get().getElementById("topbar").getStyle().
setBackgroundImage(HomePageClientBundle.INSTANCE.topbar2().getSafeUri().asString());

does not display the image.

idont want to use GQuery because it generates heavy javascript.

Thanks
Deepak



--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.



--
Deepak Singh

Thomas Broyer

unread,
Nov 22, 2011, 2:44:30 PM11/22/11
to google-we...@googlegroups.com, gwtquery
In CSS, you use background-image: url(...);, so you should do the same in GWT: setBackgroundImage("url(" + x + ")").

But in this case I'd rather use a CssResource.

Oh, and you should add an @ImageOptions(repeatStyle=Vertical) (or Both, depending on the width of your element) or you'll see other images in IE6 and IE7, or IE8 when using HTTPS (they don't use data: URLs, they use spriting, just like ImageBundle; you can also disable the use of data: URLs in your gwt.xml)

Deepak Singh

unread,
Nov 22, 2011, 3:06:19 PM11/22/11
to google-we...@googlegroups.com
Thanks Thomas.

it works like a charm now.

Thanks
Deepak

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.



--
Deepak Singh

Julien Dramaix

unread,
Nov 23, 2011, 1:38:46 AM11/23/11
to gwtq...@googlegroups.com, google-we...@googlegroups.com
> idont want to use GQuery because it generates heavy javascript.
Indeed, GQuery produces extra javascript code when you use the CSS
class (and only if you use it) due to the static initializer of this
class. We are aware of this problem. An issue exists to track it and
should be resolved soon :
http://code.google.com/p/gwtquery/issues/detail?id=107

By waiting that this issue is fixed you can use the following workaround :

$("#topbar").css("backgroundImage",
UriValue.url(HomePageClientBundle.INSTANCE.topbar2().getSafeUri().asString())..getCssName());


Julien

> "gwtquery" group.
> To post to this group, send email to gwtq...@googlegroups.com.


> To unsubscribe from this group, send email to

> gwtquery+u...@googlegroups.com.


> For more options, visit this group at

> http://groups.google.com/group/gwtquery?hl=en.
>

Reply all
Reply to author
Forward
0 new messages