Java Vaadin-在新的Vaadin 7.4网格中使用FontAwesome渲染链接图标

Java Vaadin-在新的Vaadin 7.4网格中使用FontAwesome渲染链接图标,java,vaadin,Java,Vaadin,在Vaadin 7.4之前,我使用了一个渲染为FontAwesome图标(又名LinkButton)的链接。使用BeanItemContainer,我们通过添加生成的列来实现这一点,如下所示: table.addGeneratedColumn(FIELD_SHOW_DETAILS_LINK, new Table.ColumnGenerator() { private static final long serialVersionUID = 1L;

在Vaadin 7.4之前,我使用了一个渲染为FontAwesome图标(又名LinkButton)的链接。使用BeanItemContainer,我们通过添加生成的列来实现这一点,如下所示:

        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;
            }
        });
  .fa {
    font-family: FontAwesome;
    color: gray;
    text-decoration: none;
    font-weight: normal;
    padding-left: 5px;
    padding-right: 5px;
  }
CSS样式如下:

        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;
            }
        });
  .fa {
    font-family: FontAwesome;
    color: gray;
    text-decoration: none;
    font-weight: normal;
    padding-left: 5px;
    padding-right: 5px;
  }
我尝试使用带有addGeneratedProperty方法的PropertyValueGenerator为新网格“翻译”这一点。但这并没有奏效,布局只是显示了Link类的对象表示法


非常感谢任何帮助

您可以在GeneratedPropertyContainer中添加生成的属性,该容器返回字符串属性(FontAwesome.XXX.getHtml()),并向网格中的该列添加HTML呈现程序

添加属性的步骤

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;
        }
    });

这很有效,谢谢你!现在,从PropertyValueGenerator的getValue()方法以HTML链接的形式返回该值。