per_jansson
per_jansson

Reputation: 2189

Change source CSS at runtime when using GWT and ClientBundle

I have a ClientBundle:

public interface Resources extends ClientBundle {

    @Source("styles/styles.css")
    Layout styles();

    @Source("styles/styles2.css")
    Styles styles2();

}

In my UiBinder xml I use this class like this:

<ui:with field='resources' type='com.nordea.omega.gwt.client.ui.AppResources' />
...
<div class="{resources.styles.label}">Text</div>

Standard is that styles.css is used, but is it possible at runtime change to use styles2.css instead?

Upvotes: 3

Views: 3422

Answers (2)

Christian Achilli
Christian Achilli

Reputation: 5707

If you use CSS resources it's quite easy to access them programmatically: check this http://code.google.com/webtoolkit/doc/latest/DevGuideUiBinder.html#Programmatic_access

The key code being:

@UiField AppResources resources;

Upvotes: 1

Miguel Ping
Miguel Ping

Reputation: 18347

If you use GWT-style annotations, AFAIK it will not be possible to change that dynamically because the annotations/classes are resolved statically, ie, when GWT compiles (last time I used GWT it was around a year or so).

The best way would be to navigate the DOM and change the linked style.css to another stylesheet. Check the showcase src for an example of how to do this:

http://code.google.com/p/google-web-toolkit/source/browse/branches/crawlability/samples/showcase/src/com/google/gwt/sample/showcase/client/Showcase.java?r=5652#514

Upvotes: 1

Related Questions