I resolved this issue by creating my own ButtonCell class. Following is my code:
import com.google.gwt.cell.client.AbstractSafeHtmlCell;
import com.google.gwt.cell.client.ValueUpdater;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.text.shared.SafeHtmlRenderer;
import com.google.gwt.text.shared.SimpleSafeHtmlRenderer;
/**
* A {@link Cell} used to render a button.
*/
public class ClickImage extends AbstractSafeHtmlCell<String> {
/**
* Construct a new ButtonCell that will use a {@link SimpleSafeHtmlRenderer}.
*/
private String bgImage="";
public ClickImage()
{
this(SimpleSafeHtmlRenderer.getInstance());
}
public ClickImage(String bgImage)
{
this(SimpleSafeHtmlRenderer.getInstance());
this.bgImage=bgImage;
}
public String getBgImage()
{
return bgImage;
}
public void setBgImage(String bgImage)
{
this.bgImage = bgImage;
}
/**
* Construct a new ButtonCell that will use a given {@link SafeHtmlRenderer}.
*
* @param renderer a {@link SafeHtmlRenderer SafeHtmlRenderer<String>} instance
*/
public ClickImage(SafeHtmlRenderer<String> renderer) {
super(renderer, "click", "keydown");
}
@Override
public void onBrowserEvent(Context context, Element parent, String value,
NativeEvent event, ValueUpdater<String> valueUpdater) {
super.onBrowserEvent(context, parent, value, event, valueUpdater);
if ("click".equals(event.getType())) {
onEnterKeyDown(context, parent, value, event, valueUpdater);
}
}
@Override
public void render(Context context, SafeHtml data, SafeHtmlBuilder sb)
{
String img=getBgImage();
String disableButton="";
if(img.equals("transparentButton"))
{
disableButton = "disabled=\"disabled\"";
}
sb.appendHtmlConstant("<button class=\""+img+"\" type=\"button\" "+disableButton+" tabindex=\"-1\">");
if (data != null) {
sb.append(data);
}
sb.appendHtmlConstant("</button>");
}
@Override
protected void onEnterKeyDown(Context context, Element parent, String value,
NativeEvent event, ValueUpdater<String> valueUpdater) {
if (valueUpdater != null) {
valueUpdater.update(value);
}
}
}
So I used a button to show the image. I used css to make the background color for the button to be transparent and also, I'm passing the link to the image as a parameter to the constructor when the button is being created, that way I can create different clickable images. This worked for me!