2012-04-25 115 views
0

我有一些vaadin表單在事件後重新加載。該事件導致一些字段變爲空。這意味着表單顯示字段的標籤和「null」。在加載事件後,我希望標籤和「null」值都消失。我也想這樣做而不加載一個不同的窗體來替換窗體的空值。vaadin表單無法隱藏空字段

我對形式下面的構造:

public IInfoForm(Info info) { 
    List<Object> orderedProperties =Arrays.asList(InfoContainer.DISPLAYED_FIELDS); 
    setItemDataSource(new BeanItem(idInfo), orderedProperties); 

的信息容器從一個web服務檢索數據和DISPLAYED_FIELDS列出了要顯示的字段。
我試圖尋找屬性來設置表單域,但無濟於事。

回答

1

您可以爲任何字段設置一個代表空值的特殊值。例如:

TextField textfield = new TextField(); 
textfield.setNullRepresentation("abc"); 

因此,而不是空「abc」表示在文本字段中。

自己創建字段並添加它們或將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; 
    } 
}); 
0

我會嘗試這樣做,我刪除從orderedProperties列表空值的字段和調用

setItemDataSource(new BeanItem(idInfo), orderedProperties); 

與該名單。