What is more preferable to use <ui:style>
or write class
in css
file for HTML
elements (for GWT Widgets
) in GWT ui.xml
file. I know that if to use <ui:style>
so the class
attribute has very difficult name. Help me please find out when to use <ui:style>
<ui:style>
.panel {
width: 100%;
}
.decPanel {
height:100%;
}
</ui:style>
<g:HTMLPanel addStyleNames='{style.panel}'>
<fieldset addStyleNames='{style.decPanel}'>
<legend>
...
</legend>
</fieldset>
</g:HTMLPanel>
and when to use class
CSS file
.panel {
width: 100%;
}
.decPanel {
height:100%;
}
ui.xml file
<g:HTMLPanel class="panel">
<fieldset class="decPanel">
<legend>
...
</legend>
</fieldset>
</g:HTMLPanel>
It might help you to understand the advantage of using
<ui:style>
over constant static class name.Hello Stylish World
With the
<ui:style>
element, you can define the CSS for your UI right where you need it.Sample:
Advantage
A CssResource interface is generated for you, along with a ClientBundle. This means that the compiler will warn you if you misspell the class name when you try to use it (e.g.
{style.prettty}
).Also, your CSS class name will be obfuscated, thus protecting it from collision with like class names in other CSS blocks—no more global CSS namespace!
Note: Most real world projects will probably keep their CSS in a separate file. In the example given below, the src values are relative to the location of the ui.xml file.
Sample
Prefer
<span class='{otherStyle.pretty}'
instead of<span class='pretty'
.======================
EDIT
As per suggestion by @Thomas in comments, prefer to use
<ui:with>
Sometimes your template will need to work with styles or other objects that come from outside of your template. Use the
<ui:with>
element to make them available.Refer GWT documentation on Using an external resource