Java 绑定到SQLContainer的Vaadin表,如何将字段类型显示为链接

Java 绑定到SQLContainer的Vaadin表,如何将字段类型显示为链接,java,vaadin,vaadin7,Java,Vaadin,Vaadin7,我使用Vaadin的表并使用SQLContainer设置数据: 现在,我想将此字段作为表列中的链接。 因为我直接通过SQLCOntainer设置所有字段,所以我不确定如何从中更改单个字段的外观 有人能帮忙吗?您可以使用TableFieldFactory提供自己的类型映射 只需在表中指定自己的类,就可以了 请看这里: 具有内联类的示例: // Set a custom field factory that overrides the default factory table.se

我使用Vaadin的表并使用SQLContainer设置数据:

现在,我想将此字段作为表列中的链接。 因为我直接通过SQLCOntainer设置所有字段,所以我不确定如何从中更改单个字段的外观


有人能帮忙吗?

您可以使用TableFieldFactory提供自己的类型映射

只需在表中指定自己的类,就可以了

请看这里:

具有内联类的示例:

    // Set a custom field factory that overrides the default factory
    table.setTableFieldFactory(new DefaultFieldFactory() {
        private static final long serialVersionUID = 8585461394836108250L;

        @Override
        public Field createField(Container container, Object itemId,
                Object propertyId, Component uiContext) {
            // Create fields by their class
            Class<?> cls = container.getType(propertyId);

            // Create a DateField with year resolution for dates
            if (cls.equals(Date.class)) {
                DateField df = new DateField();
                df.setResolution(DateField.RESOLUTION_YEAR);
                return df;
            }

            // Create a CheckBox for Boolean fields
            if (cls.equals(Boolean.class))
                return new CheckBox();

            // Otherwise use the default field factory 
            return super.createField(container, itemId, propertyId,
                                     uiContext);
        }
    });

将列值显示为这样的链接的最佳方法是通过调用
生成器本身可以访问备份容器属性并返回com.vaadin.ui.Link的实例。对于列ID,您可以使用现有容器ID对容器列进行阴影处理。

专家您好,这里有人可以帮忙吗?您好,在这种情况下,我每次都需要手动添加它。这和不使用.setContainer一样好,但我自己添加所有字段。这种理解正确吗?嗨,安德烈,你能举个例子吗?关键是有9个字段来自数据库,其中只有1个必须是链接。我更喜欢使用stick.setContainer而不是编码来添加所有字段。如果在这种情况下可以使用TableFieldFactory,您能分享一些代码示例吗?我在答案中添加了一个示例
    // Set a custom field factory that overrides the default factory
    table.setTableFieldFactory(new DefaultFieldFactory() {
        private static final long serialVersionUID = 8585461394836108250L;

        @Override
        public Field createField(Container container, Object itemId,
                Object propertyId, Component uiContext) {
            // Create fields by their class
            Class<?> cls = container.getType(propertyId);

            // Create a DateField with year resolution for dates
            if (cls.equals(Date.class)) {
                DateField df = new DateField();
                df.setResolution(DateField.RESOLUTION_YEAR);
                return df;
            }

            // Create a CheckBox for Boolean fields
            if (cls.equals(Boolean.class))
                return new CheckBox();

            // Otherwise use the default field factory 
            return super.createField(container, itemId, propertyId,
                                     uiContext);
        }
    });