HtmlRenderer Grid Clicks

Hi All,

I am trying to use the HtmlRenderer to display an html input field that can be clicked on without entering edit mode.

However, Grid does not allow this, and all clicks in the cell are forwarded to the grid.

I thought about making a custom renderer, but documentation on creating renderers is lacking. EX: The project structure to create a custom renderer is unclear, it’s unclear if renderers need their own gwt.xml file, there are few tutorials describing how to create a custom renderer inside of an existing project.

Does anyone have any suggestions? It woul dbe much appreciated.

The project structure for renderers is just like for client/server-side integration projects, as
described here
. Instead of a widget and widget connector you have a renderer and its connector, as
described here
. And on the server-side, the server-side renderer class.

I’m not sure if there’s a better way to solve your problem than a custom renderer. If the Grid steals the clicks from HTML inputs, then that’s how it is. Using a HtmlRenderer like that sounds a bit hacky anyhow, so perhaps a custom renderer would be the proper way to go.

Got it. To get my feet wet I’ve tried extending a label much like the ButtonRenderer does for a buttton, and all I end up seeing is a blank grid.

Here is the code:

Connector

[code]
package com.company.renderers.htmlclickrenderer.client;

import com.google.web.bindery.event.shared.HandlerRegistration;
import com.vaadin.client.connectors.ClickableRendererConnector;
import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler;
import com.vaadin.shared.ui.Connect;

import elemental.json.JsonObject;

@Connect(com.ipl.renderers.htmlclickrenderer.HtmlClickRenderer.class)
public class HtmlClickRendererConnector extends
ClickableRendererConnector {

@Override
public HtmlClickRenderer getRenderer() {
    return (HtmlClickRenderer) super.getRenderer();
}

@Override
protected HandlerRegistration addClickHandler(
        RendererClickHandler<JsonObject> handler) {
    return getRenderer().addClickHandler(handler);
}

}
[/code]The client renderer:

[code]
package com.company.renderers.htmlclickrenderer.client;

import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.ui.Label;
import com.vaadin.client.renderers.ClickableRenderer;
import com.vaadin.client.widget.grid.RendererCellReference;

public class HtmlClickRenderer extends ClickableRenderer<String, Label> {

@Override
public Label createWidget() {
    Label label = GWT.create(Label.class);
    label.addClickHandler(this);
    return label;
}

@Override
public void render(RendererCellReference cell, String data, Label widget) {
    widget.setText(data);
}

}
[/code]The server renderer:

[code]
package com.company.renderers.htmlclickrenderer;

import com.vaadin.ui.renderers.ClickableRenderer;
public class HtmlClickRenderer extends ClickableRenderer {

private static final long serialVersionUID = -5598702155879346813L;


public HtmlClickRenderer() {
    super(String.class);
}


public HtmlClickRenderer(RendererClickListener listener) {
    this();
    addClickListener(listener);
}

}
[/code]Located in resources/com/company/renderers/htmlclickrenderer/WidgetSet.gwt.xml:

[code]

<?xml version="1.0" encoding="UTF-8"?> [/code]Finally I've added the following line to my main AppWidgetSet.gwt.xml: [code] [/code] I've tried compiling the WidgetSet.gwt.xml with the Eclipse plug-in, I've tried compiling just AppWidgetSet.gwt.xml, and I've tried compiling both widgetsets.

Any ideas on what I am doing wrong?

Hi again,

Your code looks good at least with a quick look, although I can’t be sure if some detail causes the trouble. Your way of modularizing the custom client-side code in a separate GWT module is probably a good way. In such case, you may want to have the following line in such a sub-module to prevent it from being automatically regenerated if you have edited it manually (it actually shouldn’t be if you are just including it from the project widget set):

    <!-- WS Compiler: manually edited  -->

You only need to compile the AppWidgetSet, as it includes the widget set containing the renderer, and make sure it’s configured for the UI either in the @VaadinConfiguration or in web.xml.

Otherwise, I don’t know what causes your problem; it’s rather common that there’s some simple mistake or that you have left something uncompiled or compiled with wrong version; stopping the server, cleaning it, and redeploying is often necessary in Eclipse at least. The debug window at least tells if the widget set is compiled properly, and also if there’s some client-side errors.