【问题标题】:vaadin : multiple links in one field on the tablevaadin : 表格的一个字段中的多个链接
【发布时间】:2016-11-28 23:39:34
【问题描述】:

我想问一下vaadin的UI,也就是Table。 如果我使用了这个组件,那么我必须使用这个命令来创建一个字段:

userTable.addContainerProperty("Status", String.class, "Active");

如果我想在这个字段中创建链接,那么我必须这样做:

userTable.addContainerProperty("Action", Link.class, new Link("Remove", new ExternalResource("#")));

我的问题是,上面的示例仅在一个字段中显示单个链接,即 REMOVE Link。我想在该表的一个字段中创建两个链接。例如“操作”字段下方的 EDIT 和 DELETE 链接,我该怎么做?

【问题讨论】:

    标签: vaadin


    【解决方案1】:

    使用生成的列将组件添加到每一行。创建一个水平布局和两个按钮作为内容。

    class ValueColumnGenerator implements Table.ColumnGenerator {
    String format; /* Format string for the Double values. */
    
    /**
     * Creates double value column formatter with the given
     * format string.
     */
    public ValueColumnGenerator(String format) {
        this.format = format;
    }
    
    /**
     * Generates the cell containing the Double value.
     * The column is irrelevant in this use case.
     */
    public Component generateCell(Table source, Object itemId,
                                  Object columnId) {
        // Get the object stored in the cell as a property
        Property prop =
            source.getItem(itemId).getItemProperty(columnId);
        if (prop.getType().equals(Double.class)) {
            HorizontalLayout hbox = new HorizontalLayout()
            hbox.addComponent(new Button("Status"))
            hbox.addComponent(new Button("Remove"))
            return hbox;
        }
        return null;
    }
    }
    

    有关详细信息,请参阅《瓦丁之书》第 5.14.5 节:

    https://vaadin.com/book/-/page/components.table.html

    【讨论】:

    【解决方案2】:

    您可以将此按钮添加到 Horizo​​ntalLayout 或任何其他容器组件。然后将此布局添加到表中的容器属性中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-15
      • 1970-01-01
      • 2020-10-16
      • 2013-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多