Vaadin - Render Link-Icon using FontAwesome inside new Vaadin 7.4 Grid

3.8k Views Asked by At

I used a link rendered as a FontAwesome-Icon (aka LinkButton) before Vaadin 7.4. Using the BeanItemContainer we did so by adding generated columns like this:

        table.addGeneratedColumn(FIELD_SHOW_DETAILS_LINK, new Table.ColumnGenerator() {
            private static final long serialVersionUID = 1L;

            @Override
            public Object generateCell(final Table source, final Object itemId, Object columnId) {
                final Link link = new Link();
                link.setDescription("Show details");
                link.setIcon(FontAwesome.SEARCH);
                link.setResource(new ExternalResource("#!details/" 
                  + ((MainVO) itemId).getUid() + "?mode=VIEW"));
                link.addStyleName("fa");
                return link;
            }
        });

With the CSS-Style like this:

  .fa {
    font-family: FontAwesome;
    color: gray;
    text-decoration: none;
    font-weight: normal;
    padding-left: 5px;
    padding-right: 5px;
  }

I tried to "translate" this for the new Grid using a PropertyValueGenerator with the addGeneratedProperty-method. But that did not work out, the layout just shows the object notation of the Link-class.

Any help much appreciated!

1

There are 1 best solutions below

1
On

You can add a generated property within the GeneratedPropertyContainer which returns a String Property (FontAwesome.XXX.getHtml()) and add a HTML-Renderer to that column in the grid.

To add the Property

GeneratedPropertyContainer gpc = new GeneratedPropertyContainer(your_collection);
gpc.addGeneratedProperty("download", new PropertyValueGenerator<String>() {
        @Override
        public String getValue(Item item, Object itemId, Object propertyId) {
            return FontAwesome.WARNING.getHtml();
        }

        @Override
        public Class<String> getType() {
            return String.class;
        }
    });

and to add the Renderer:

grid.getColumn("download").setRenderer(new HtmlRenderer());