CssResource - common style - good practice

27 views
Skip to first unread message

Christopher Z.

unread,
Jan 24, 2012, 5:49:42 AM1/24/12
to Google Web Toolkit
Hello,

I have 5 views(.ui.xml). On every view i paste soemthing like that:

<ui:style src="../MyStyle.css" />

and on every button on every page I put styleName attribute:

<g:Button ui:field="buttonName" styleName="{style.myButtonStyle}" />

My Question is: Do I have to do this for all my buttons ? I would like
to do something general style for this kind of widget .
What is good practice for this case?








Thomas Broyer

unread,
Jan 24, 2012, 6:10:16 AM1/24/12
to google-we...@googlegroups.com
If this is really for *every* button, then you can use the gwt-Button CSS class name, that's automatically added by each button in the constructor. In a CssResource, make sure you have an "@external .gwt-Button;" line to selectively disable obfuscation for that class name.
That way, you only ever have to inject your CssResource *once* for your whole app.

If you need to keep things "per button", then instead of using the same *.css source in many CssResource (<ui:style> generates a CssResource), which will result in your styles duplicated for each *.ui.xml file (CSS class names would be obfuscated with different names), then create a CssResource interface with the @Source("MyStyle.css"), put it in a ClientBundle, GWT.create() and ensureInjected() it somewhere (e.g. in your onModuleLoad), and then use it in your *.ui.xml with a <ui:with> (see http://code.google.com/webtoolkit/doc/latest/DevGuideUiBinder.html#Using_an_external_resource ).
Reply all
Reply to author
Forward
0 new messages