antony.trupe
antony.trupe

Reputation: 10844

Obfuscated class names aren't added to the stylesheet when added to Cells

The obfuscated class name(GPGOA3-B) is indeed being added to the cell, but the class itself isn't being added to any stylesheet.

What am I doing wrong?

public final class HyperlinkCell extends AbstractCell<HyperlinkCellData> {

    // TODO
    private interface MyCss extends CssResource {
        String red();
    }

    // TODO
    private interface MyResources extends ClientBundle {
        @Source("HyperlinkCell.css")
        MyCss css();
    }

    // TODO
    private static MyResources resources = GWT.create(MyResources.class);

    HyperlinkCell() {
        super("click");
    }

    @Override
    public void onBrowserEvent(Element parent, HyperlinkCellData value,
            Object key, NativeEvent event,
            ValueUpdater<HyperlinkCellData> valueUpdater) {
        // handle click event
        History.newItem(value.targetHistoryToken, true);
    }

    @Override
    public void render(HyperlinkCellData value, Object key, SafeHtmlBuilder sb) {
        String childGroupObfuscatedClass = resources.css().red();
        sb.append(SafeHtmlUtils.fromTrustedString("<a class=\""))
                .append(SafeHtmlUtils
                        .fromTrustedString(childGroupObfuscatedClass))
                .append(SafeHtmlUtils.fromTrustedString("\""))
                .append(SafeHtmlUtils.fromTrustedString(" href=\"#"))
                .append(SafeHtmlUtils.fromString(value.targetHistoryToken))
                .append(SafeHtmlUtils.fromTrustedString("\">"))
                .append(SafeHtmlUtils.fromString(value.text))
                .append(SafeHtmlUtils.fromTrustedString("</a>"));
    }
}

HyperlinkCell.css

.red {
    color: red;
}

resulting DOM element

<a href="#target" class="GPGOA3-B">text</a>

Upvotes: 0

Views: 114

Answers (1)

antony.trupe
antony.trupe

Reputation: 10844

MyResources.resources.css().ensureInjected();

Calls com.google.gwt.dom.client.StyleInjector.injectStylesheet(String) to inject the contents of the CssResource into the DOM. Repeated calls to this method on an instance of a CssResources will have no effect.

Upvotes: 1

Related Questions