Tuesday, August 28, 2012

Re: Override body style with CssResource

Thank you Jens. That's exactly what I missed (StandardResources). Instead of making the modified css as pat of my ClientBundle, I serve it as a flat CSS file. It works perfectly! I thought this should be a rather common thing to do but apparently not....

Charles


On Tuesday, August 28, 2012 2:11:24 PM UTC-4, Jens wrote:
You can inherit StandardResources.gwt.xml instead of Standard.gwt.xml. When you do so, only the images used by the standard theme will be copied to your app folder and no CSS will be automatically included in your host page.

Then you create a new css file and copy everything from gwt's theme to your new css file and make modifications to it. Then you create a ClientBundle like

interface AppClientBundle extends ClientBundle {

  @Source("yourModifiedTheme.css")
  @NotStrict //Not sure if its needed but I guess it is.
  CssResource themeCss();

}

and instantiate it in your onModuleLoad():

public void onModuleLoad() {
  AppClientBundle bundle = GWT.create(AppClientBundle.class);
  bundle.themeCss().ensureInjected(); //injects the CSS into the HTML page.
}


The result is:
- The CSS code is now embedded in your JavaScript file, which saves a download request (you dont have a <link href="theme.css" .... /> tag anymore)
- You can control when the CSS should be injected into your HTML file during app startup.

-- J.

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

No comments:

Post a Comment