我有一些在事件发生后重新加载的vaadin表单。该事件导致某些字段变为空。这意味着表单显示字段的标签和" null"。我想要标签和" null"加载事件后消失的值。我还想这样做而不加载不同的表单来用空值替换表单。
我有以下形式的构造函数:
public IInfoForm(Info info) {
List<Object> orderedProperties =Arrays.asList(InfoContainer.DISPLAYED_FIELDS);
setItemDataSource(new BeanItem(idInfo), orderedProperties);
信息容器从Web服务中检索数据,DISPLAYED_FIELDS列出要显示的字段。
我试图寻找在表单字段上设置的属性,但无济于事。
答案 0 :(得分:1)
您可以为任何字段设置一个代表空值的特殊值。例如:
TextField textfield = new TextField();
textfield.setNullRepresentation("abc");
因此,在文本字段中表示“abc”而不是null。
自己创建字段并添加它们或向表单添加FieldFactory。
Form form = new Form();
form.setFormFieldFactory(new FormFieldFactory() {
public Field createField(Item item, Object propertyId,
Component uiContext) {
Field field = DefaultFieldFactory.get().createField(item,
propertyId, uiContext);
if (field instanceof TextField) {
((TextField) field).setNullRepresentation("abc");
}
return field;
}
});
答案 1 :(得分:0)
我会尝试这样做,我从orderedProperties列表中删除带有null值的字段并调用
setItemDataSource(new BeanItem(idInfo), orderedProperties);
列表。