tags:

views:

275

answers:

1

Hello there,

I created a few styles into a CSSResource and it works well whether I use

GWT.<MyResources>create(MyResources.class).myStyles().ensureInjected();

or not.

Could anyone shed a light on this and explain when to use ensureInjected or not?

Thank you! Daniel

A: 

Good question - one situation that comes to my mind is when you want to use styles from some global stylesheet in a UiBinder template - then you need to call ensureInjected to... ensure the styles are indeed injected when you are referencing them (the "local" UiBinder styles, that you define in xml are automagically injected).

You can see this used as such in the Mail example:

public void onModuleLoad() {
    // Inject global styles.
    GWT.<GlobalResources>create(GlobalResources.class).css().ensureInjected();

    // Create the UI defined in Mail.ui.xml.
    DockLayoutPanel outer = binder.createAndBindUi(this);

    // ...rest of the code
}

Note how ensureInjected is called before binding the UI.

This is the only situation I know that warrants using ensureInjected, but maybe I missed something.

Igor Klimer
Yes, I understood this as well but: I am using a global css file and it works well whether I use ensureInjected or not. This is the mystery I am try to solve.