I Help help implementing ClickableSafeHtmlCell

51 views
Skip to first unread message

Milan Cvejic

unread,
Oct 30, 2012, 9:31:58 PM10/30/12
to google-we...@googlegroups.com
Hi,
I am trying to implement ClickableSafeHtmlCell but I can not make it to handle events. I am using Field

    class ClickableSafeHtmlCell extends SafeHtmlCell {

        public void onBrowserEvent(Cell.Context context, Element parent, SafeHtml value, NativeEvent event, ValueUpdater<SafeHtml> valueUpdater) {
            super.onBrowserEvent(context, parent, value, event, valueUpdater);
            if ("click".equals(event.getType())) {
                Window.alert("bla");
            }
        }
    }

and then creating CellTable column with following code:

        Column<Data, SafeHtml> objectNameColumn = new Column<Data, SafeHtml>(new ClickableSafeHtmlCell()) {
            @Override
            public SafeHtml getValue(ModuleEntry object) {
                String name = (object.getName() == null ? "" : object.getName());
                String description = (object.getDescription() == null ? "" : object.getDescription());

                String regex = "(<([^>]+)>)";
                return new SafeHtmlBuilder().appendHtmlConstant(
                        "<span>" + name + "</span></br />" + "<span title='" + new SafeHtmlBuilder().appendEscaped(description.replaceAll(regex, "")).toSafeHtml().asString() + "'>"
                                + description.replaceAll(regex, "") + "</span>").toSafeHtml();
            }
        };
and set FieldUpdater for that column:

        objectNameColumn.setFieldUpdater(new FieldUpdater<Data, SafeHtml>() {
            public void update(int index, Data object, SafeHtml value) {
                Window.alert(value.asString());
            }
        });

Is there anything that I am missing? Any suggestion is welcome.

Thanks,
Milan

Andrea Boscolo

unread,
Oct 31, 2012, 5:20:25 AM10/31/12
to google-we...@googlegroups.com
If you want your cell to handle events you need to set those events as consumed by defining a constructor like

public ClickableSafeHtmlCell(SafeHtmlRenderer<String> renderer) {
  super(renderer, "click");
}

But do not reinvent the wheel, http://google-web-toolkit.googlecode.com/svn/javadoc/2.5/com/google/gwt/cell/client/ClickableTextCell.html is already there (that also is a safehtmlcell).
Reply all
Reply to author
Forward
0 new messages