tags:

views:

688

answers:

3

The following replaces any current css class names. It appears to call setStyleName.

<g:DecoratorPanel styleName="{style.myCssClass}">

What I really want to do is add a class name, like calling addStyleName.

Is it possible to do what I'm attempting?

+4  A: 

Use addStyleNames in such situations, like this:

<g:DecoratorPanel addStyleNames="{style.myCssClass}">

It's a little trick I picked up on the GWT's Google Group - too bad it's not (?) mentioned in the official documentation.

PS: I'm actually missing a really comprehensive documentation for UiBinder. I grepped the GWT sources for addStyleNames and found this file: WidgetBasedUi.ui.xml - it seems to contain some interesting use cases for UiBinder, including the one with addStyleNames.
If someone knows any other good/secret references for UiBinder, please share :)

Igor Klimer
I was close. I tried that, but missed the pluralization of the function name(addStyleName instead of addStyleNames).
antony.trupe
The documentation at http://code.google.com/webtoolkit/doc/latest/DevGuideUiBinder.html#Hello_Stylish_World is fairly complete, and mentions the attribute. It is however more of a guide than a reference manual.
Paul de Vrieze
A: 

But what if you want cascading styles... For example, you have a menubar comosed of menuitems and so in the css, I've defined different styles liket that:

.gwt-MenuBar {
cursor: default;
}
.gwt-MenuBar .gwt-MenuItem {
cursor: default;
}
.gwt-MenuBar .gwt-MenuItem-selected {
background: #E0EDFE;
}

Is it possible to have something like:

<g:MenuBar ui:field="menuBar" addStyleNames="{style.gwt-MenuBar}"></g:MenuBar>  

and the style for the menuItem will be automatically applied? Actually, the menuItem are added in the java class. It seems to not working, but I don't know why? I didn't get the philosophy or just a wrong method?

Gerald
Hi Gerald. This isn't a forum. Ask a new question don't "answer" existing once.
Eduard Wirch
+2  A: 

Yes addStyleNames is the solution. And it is actually mentioned in the documentation: UiObject. See section "Use in UiBinder Templates".

Eduard Wirch