per_jansson
per_jansson

Reputation: 2189

How to access regular CSS from GWT widget?

Is it possible to access a regular CSS selector in a regular CSS, imported via module XML, in a GWT widget? Or do I, and should I, create a CssResource?

Edit: I forgot to specify that I want to access the CSS selector in a widget from a UiBinder XML file.

Upvotes: 0

Views: 404

Answers (2)

John
John

Reputation: 857

I would say if the style is used across multiple widgets it's better to use a CssResource. It seems to be the way the google team is moving with everything, and it ensures that the style actually exists - using a arbitrary string allows typos and doesn't keep up with changes to the css file. Also, I believe I read on the gwt google group that including a stylesheet in the module was/is being deprecated, I can't find the posting now though.

So make the CssResource:

package the.package.of.the.client.bundle;

public interface MyBundle extends ClientBundle {

    static MyBundle INSTANCE = GWT.create(MyBundle.class);

    @Source("myCss.css")
    MyCss myCss();

        @Shared
    public interface CommonCss extends CssResource {
        String myStyle();
    }
}

Then in the UiBinder:

<ui:with field='myname' type='the.package.of.the.client.bundle' />

<g:Label addStyleNames="{myname.myCss.myStyle}" text="My Label Text"/>

Upvotes: 0

Riley Lark
Riley Lark

Reputation: 20890

You can use widget.addStyleName("regularoldcssselectorname") and your parameter will come through in the final HTML as a class name.

Upvotes: 3

Related Questions