2014-01-20 57 views

回答

1

一種選擇是使用自定義TableFieldFactory,然後將偵聽器添加到需要它的每個字段。

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

table.setTableFieldFactory(new MyTableFieldFactory()); 

... 

public class MyTableFieldFactory extends DefaultFieldFactory { 

    @Override 
    public Field createField(Container container, Object itemId, 
      Object propertyId, Component uiContext) { 
     String prop = (String) propertyId; 
     if ("a".equals(prop)) { // propertyId of the column you wish to change 
      AbstractField f = (AbstractField) super.createField(container, itemId, propertyId, uiContext); // casting to AbstractField to set the field to immediate mode 
      f.setImmediate(true); 
      f.addValueChangeListener(new Property.ValueChangeListener() { 
       @Override 
       public void valueChange(ValueChangeEvent event) { 
        String val = (String) event.getProperty().getValue(); 
        val = val.replace(".", ","); 
        event.getProperty().setValue(val); 
       } 
      }); 
      return f; 
     } 
     return super.createField(container, itemId, propertyId, uiContext); 
    } 
} 
+0

代碼工作正常,但Vaadin在您的代碼替換值之前更改...並顯示此代碼。值輸入= 1124.14和Vaadin品脫112,414。你的代碼很好,但Vaadin開玩笑說我。 – Brumanuel

相關問題