Tuesday, September 14, 2010

Re: UiBinder CSS class renaming

On Sep 13, 5:53 am, "hendrix.jason" <hendrix.ja...@gmail.com> wrote:
> I'm using uibinder where i have defined a <style> in the ui.xml file.
> I have a list of hyperlinks being used as a menu. I have a class
> defined for "current page" so that I can change the background color
> of the link if you are currently on that page.
>
> So I want to programmatically change the class for that certain
> hyperlink.
>
> I can use the setStyleName command from the .java file and it does set
> the name to whatever I type. However, the name for the class that I
> typed directly in to the ui.xml file has been changed by gwt to be a
> random string, so the two class names no longer match.
>
> Is there somehow I can get the random generated name, or somehow
> reference it?
>
> I've tried using an external css file and gwt stil seems to change the
> name of the classes to a random string even when using an external css
> file.

Here's some sample code to give you access to your <ui:style>'s
defined class within Java:

interface Style extends CssResource {
public String currentPage();
}

@UiField Style style;

<ui:style type="path.to.Style">
.currentPage { ... }
</ui:style>

UiBinder will then generate CssResource that extends your Style
interface, instead of CssResource; and it will inject it into your
"style" @UiField (because this is the default name of <ui:style> when
it doesn't have an explicit field="" attribute, you're free to change
the field name), so you can use it from within your code:

myLink.addStyleName(style.currentPage());
myOtherLink.removeStyleName(style.currentPage());

I usually put the Style interface as an inner interface of the
UiBinder owner class.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
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