Project

General

Profile

Revision 4132369c

ID4132369c50c19a05185477eff2f70b8ded56678f
Parent 5a92c416
Child a136d47b

Added by Andreas Kohlbecker over 2 years ago

TextFieldNFix trim empty string to null - final FIX

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/TextFieldNFix.java
9 9
package eu.etaxonomy.cdm.vaadin.component;
10 10

  
11 11
import com.vaadin.data.Property;
12
import com.vaadin.ui.AbstractTextField;
12 13
import com.vaadin.ui.TextField;
13 14

  
14 15
/**
......
82 83
    }
83 84

  
84 85

  
85

  
86
    /**
87
     *
88
     */
89 86
    protected void init() {
90 87
        setNullSettingAllowed(true);
88
        addBlurListener(e -> {
89
            AbstractTextField c = ((AbstractTextField) e.getComponent());
90
            if (c.getValue() != null) {
91
                c.setValue(c.getValue().trim());
92
            }
93
        });
91 94
    }
92 95

  
93 96

  
94

  
95
    /**
96
     * {@inheritDoc}
97
     */
98 97
    @Override
99 98
    public String getNullRepresentation() {
100 99
        return "";
101 100
    }
102 101

  
103

  
104

  
105
    /**
106
     * {@inheritDoc}
107
     */
108
    @Override
109
    protected void setInternalValue(String newValue) {
110
        if(newValue != null){
111
            newValue = newValue.trim();
112
            if(newValue.isEmpty()){
113
                newValue = null;
114
            }
115
        }
116
        super.setInternalValue(newValue);
117
    }
102
//    @Override
103
//    protected void setValue(String newFieldValue, boolean repaintIsNotNeeded,
104
//            boolean ignoreReadOnly) {
105
//        newFieldValue = trimValue(newFieldValue);
106
//        super.setValue(newFieldValue, repaintIsNotNeeded, ignoreReadOnly);
107
//    }
108
//
109
//    @Override
110
//    protected void setInternalValue(String newValue) {
111
//        newValue = trimValue(newValue);
112
//        super.setInternalValue(newValue);
113
//    }
114
//
115
//
116
//
117
//    /**
118
//     * @param newValue
119
//     * @return
120
//     */
121
//    protected String trimValue(String newValue) {
122
//        if(newValue != null){
123
//            newValue = newValue.trim();
124
//            if(newValue.isEmpty()){
125
//                newValue = null;
126
//            }
127
//        }
128
//        return newValue;
129
//    }
118 130

  
119 131

  
120 132

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)