2

I want to build a custom renderer for some of my grids columns to hide the text if the user doesn't have the right to read it. It's still important that the data is accessible even if the user is not able to read it. So I wrote a custom renderer which looks like this:

package <package>.util.renderer;

import com.vaadin.client.renderers.Renderer;
import com.vaadin.client.widget.grid.RendererCellReference;
import <package>.util.CustomSecurityConstants;
import <package>.BaseUI;

public class BlockedStringRendererClient implements Renderer<String> {

private boolean canReadBlocked = BaseUI.getCurrentPrincipal().get().getAuthorities().contains(CustomSecurityConstants.READ_PERMISSION_BLOCKED);

@Override
public void render(RendererCellReference rendererCellReference, String s) {
    if (canReadBlocked) {
        rendererCellReference.getElement().setInnerText(s);
    } else {
            rendererCellReference.getElement().setInnerText("");
       }
   }
}

Then I wrote the server side of the renderer, following this tutorial https://vaadin.com/docs/-/part/framework/clientsidewidgets/clientsidewidgets-grid.html

package <package>.util.renderer;


import com.vaadin.ui.Grid;

public class BlockedStringRendererServer extends Grid.AbstractRenderer<String> {
    public BlockedStringRendererServer() {
        super(String.class);
    }
}

And finally the connector to connect these components:

package <package>.util.renderer;

import com.vaadin.client.connectors.AbstractRendererConnector;
import com.vaadin.shared.ui.Connect;

@Connect(BlockedStringRendererServer.class)
public class BlockedStringRendererConnector extends AbstractRendererConnector<String> {

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

}

But now when I try to use the connector like follows:

grunddatenGrid.getColumn("name").setRenderer(new BlockedStringRendererServer());

The grid doesn't show any columns that contains strings anymore.

I really don't know what I'm doing wrong but I think it might has to do with the Connector-Annotation not working as expected because when I try to debug the client side logic it doesn't even get called. Can somebody point me to what steps I'm missing?

Kind regards, Fabian

Fabian
  • 237
  • 3
  • 13
  • 1
    I guess the client-side code needs to be compiled with GWT compiler to be transformed to JavaScript. Do you have your own GWT widgetset xml file? Otherwise you should see errors in the browser console stating like missing renderer class or similar. – Steffen Harbich Apr 10 '17 at 13:33
  • 1
    See [this](https://vaadin.com/docs7/-/part7/framework/clientside/clientside-module.html) and [this](https://vaadin.com/docs7/-/part7/framework/clientside/clientside-compiling.html). Depending on your setup, you need to setup your build to invoke the GWT compiler. – Steffen Harbich Apr 10 '17 at 13:39
  • Thanks very much for the response! I'm currently trying to get the GWT-Compiler to work but I'm having some problems including the required sources to compile the Renderer. – Fabian Apr 18 '17 at 05:25
  • I included the vaadin-maven-plugin as shown in the second link of yours. Then I moved the components to the correct package structure required by GWT. My gwt.xml looks like this: – Fabian Apr 18 '17 at 05:27
  • But when I try to compile the Renderer I get the following error: `No source code is available for type com.vaadin.ui.Grid.AbstractRenderer; did you forget to inherit a required module?`. As I already inherit Vaadins Default Widget Set I'm not sure what to do at this stage. – Fabian Apr 18 '17 at 05:28
  • I think there is a dependency missing. You should try to find a working example with maven on the net. My setup is with gradle. – Steffen Harbich Apr 21 '17 at 12:53

0 Answers0