gwtuibindergwt2clientbundlecssresource

How to remove the injected CSS Resource in GWT?


I want to remove the injected CSSResource in GWT application.

I used the following code MyClass.INSTANCE.ensureInjected();

I want the above CSSResource for a particular page only. So the remaining pages should be work as per the actual css/theme.

Once I inject this then its applicable for the whole application. How can I overcome this?


Solution

  • You can inject your css bundle using directly StyleInjector utility class, instead of the ensureInjected() method

    Then you will have a reference of the injected element which you can remove when you want.

    // Equivalent to MyClass.INSTANCE.ensureInjected()
    StyleElement e  = StyleInjector.injectStylesheet(MyClass.INSTANCE.css().getText());
    
    
    // Remove the injected css element
    e.removeFromParent();