TextFieldNFix trim empty string to null - final FIX
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Fri, 8 Jun 2018 18:11:01 +0000 (20:11 +0200)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Fri, 8 Jun 2018 18:11:01 +0000 (20:11 +0200)
src/main/java/eu/etaxonomy/cdm/vaadin/component/TextFieldNFix.java

index a5e39d653916d6708d9bf45b5349db168987b0d5..364a89aba98bb7c2adc4ffb35443a44b28b55559 100644 (file)
@@ -9,6 +9,7 @@
 package eu.etaxonomy.cdm.vaadin.component;
 
 import com.vaadin.data.Property;
+import com.vaadin.ui.AbstractTextField;
 import com.vaadin.ui.TextField;
 
 /**
@@ -82,39 +83,50 @@ public class TextFieldNFix extends TextField {
     }
 
 
-
-    /**
-     *
-     */
     protected void init() {
         setNullSettingAllowed(true);
+        addBlurListener(e -> {
+            AbstractTextField c = ((AbstractTextField) e.getComponent());
+            if (c.getValue() != null) {
+                c.setValue(c.getValue().trim());
+            }
+        });
     }
 
 
-
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public String getNullRepresentation() {
         return "";
     }
 
-
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected void setInternalValue(String newValue) {
-        if(newValue != null){
-            newValue = newValue.trim();
-            if(newValue.isEmpty()){
-                newValue = null;
-            }
-        }
-        super.setInternalValue(newValue);
-    }
+//    @Override
+//    protected void setValue(String newFieldValue, boolean repaintIsNotNeeded,
+//            boolean ignoreReadOnly) {
+//        newFieldValue = trimValue(newFieldValue);
+//        super.setValue(newFieldValue, repaintIsNotNeeded, ignoreReadOnly);
+//    }
+//
+//    @Override
+//    protected void setInternalValue(String newValue) {
+//        newValue = trimValue(newValue);
+//        super.setInternalValue(newValue);
+//    }
+//
+//
+//
+//    /**
+//     * @param newValue
+//     * @return
+//     */
+//    protected String trimValue(String newValue) {
+//        if(newValue != null){
+//            newValue = newValue.trim();
+//            if(newValue.isEmpty()){
+//                newValue = null;
+//            }
+//        }
+//        return newValue;
+//    }