Wednesday, October 26, 2011

AbstractSafeHtmlCell and the events, for dummies

I was playing around the possibility to extend AbstractSafeHtmlCell and create custom cell again, now with the GWT 2.4 and had a funny beginner problem. The issue was that I wanted to override the onBrowserEvent to handle click events. Everything was looking really good, but when I click on a cell into the custom column nothing happens. So I was hacking around to find out the problem without to realize that the issue was actually something so simple. Just never copy past example codes! When you extend the AbstractSafeHtmlCell you can have for example two constructors, in my case looking like this:

    public ImagesCell() {
super(SimpleSafeHtmlRenderer.getInstance());
}

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




If you have those two constructors your custom cell will work, everything is rendered, but if you use only the first constructor to initialize the cell, the click event will be not handled. The answer of this is very simple, just don’t forget to add the events into the first constructor as well, so your code should look like this:

    public ImagesCell() {
super(SimpleSafeHtmlRenderer.getInstance(), "click", "keydown");
}

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




cheers

No comments:

Post a Comment