Revision 1026
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.spi/src/main/java/org/gvsig/tools/dynform/spi/dynformfield/AbstractJDynFormField.java | ||
---|---|---|
68 | 68 |
|
69 | 69 |
private boolean readOnly = false; |
70 | 70 |
private List customActions; |
71 |
protected boolean emptyToNull = false; |
|
71 | 72 |
|
72 | 73 |
|
73 | 74 |
public AbstractJDynFormField(DynObject parameters, |
... | ... | |
318 | 319 |
} |
319 | 320 |
} |
320 | 321 |
|
321 |
} |
|
322 |
public void setTranslateEmptyToNull(boolean emptyToNull) { |
|
323 |
this.emptyToNull = emptyToNull; |
|
324 |
} |
|
325 |
|
|
326 |
public boolean translateEmptyToNull() { |
|
327 |
return this.emptyToNull; |
|
328 |
} |
|
329 |
|
|
330 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.spi/src/main/java/org/gvsig/tools/dynform/spi/dynformfield/AbstractJDynFormFieldWithValueList.java | ||
---|---|---|
31 | 31 |
import javax.swing.JComboBox; |
32 | 32 |
import javax.swing.JTextField; |
33 | 33 |
import javax.swing.text.JTextComponent; |
34 |
import org.apache.commons.lang3.StringUtils; |
|
34 | 35 |
|
35 | 36 |
import org.gvsig.tools.dataTypes.CoercionException; |
36 | 37 |
import org.gvsig.tools.dynform.JDynFormField; |
... | ... | |
96 | 97 |
DynObjectValueItem value = (DynObjectValueItem) this.getJComboBox().getModel().getElementAt(selected); |
97 | 98 |
s = value.getValue().toString(); |
98 | 99 |
} |
99 |
} |
|
100 |
} |
|
101 |
if( StringUtils.isEmpty(s) && this.translateEmptyToNull() ) { |
|
102 |
return null; |
|
103 |
} |
|
100 | 104 |
return s; |
101 | 105 |
} |
102 | 106 |
|
103 | 107 |
public void setValue(Object value) { |
104 | 108 |
String s = null; |
105 | 109 |
if( value == null ) { |
110 |
this.setTranslateEmptyToNull(true); |
|
106 | 111 |
value = this.getDefinition().getDefaultValue(); |
107 | 112 |
if( value == null ) { |
108 | 113 |
s = this.getDefaultValue(); |
... | ... | |
110 | 115 |
s = value.toString(); |
111 | 116 |
} |
112 | 117 |
} else { |
118 |
this.setTranslateEmptyToNull(false); |
|
113 | 119 |
s = value.toString(); |
114 | 120 |
try { |
115 | 121 |
this.getDefinition().validate(value); |
... | ... | |
144 | 150 |
|
145 | 151 |
public Object getValue() { |
146 | 152 |
Object value = null; |
147 |
String s = null; |
|
148 |
if( this.contents instanceof JTextField ) { |
|
149 |
s = this.getJTextField().getText(); |
|
150 |
} else { |
|
151 |
s = this.getJComboBox().getSelectedItem().toString(); |
|
152 |
} |
|
153 |
try { |
|
154 |
value = this.getDefinition().coerce(s); |
|
155 |
} catch (CoercionException e) { |
|
156 |
throw new IllegalFieldValue(this,"Can't convert value '"+s+"' to '"+this.getDefinition().getDataType().getName()+"'."); |
|
157 |
} |
|
153 |
String s = this.getValueFromJComponent(); |
|
154 |
try { |
|
155 |
value = this.getDefinition().coerce(s); |
|
156 |
} catch (CoercionException e) { |
|
157 |
throw new IllegalFieldValue(this,"Can't convert value '"+s+"' to '"+ this.getDefinition().getDataType().getName() + "'."); |
|
158 |
} |
|
158 | 159 |
this.problemIndicator().clear(); |
159 | 160 |
return value; |
160 | 161 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformfield/String/JDynFormFieldString.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.tools.dynform.services.dynformfield.String; |
25 | 25 |
|
26 |
import org.apache.commons.lang3.StringUtils; |
|
26 | 27 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldWithValueList; |
27 | 28 |
import org.gvsig.tools.dynobject.DynObject; |
28 | 29 |
import org.gvsig.tools.service.spi.ServiceManager; |
... | ... | |
42 | 43 |
public Object getValue() { |
43 | 44 |
Object value = null; |
44 | 45 |
String s = this.getValueFromJComponent(); |
45 |
if( s.trim().length()==0 ) {
|
|
46 |
if( StringUtils.isBlank(s) ) {
|
|
46 | 47 |
Object x = this.getDefinition().getDefaultValue(); |
47 |
if( x == null ) { |
|
48 |
value = ""; |
|
49 |
} else { |
|
50 |
value = x.toString(); |
|
48 |
if( x != null ) { |
|
49 |
value = x.toString(); |
|
51 | 50 |
} |
52 | 51 |
} else { |
53 | 52 |
value = s; |
Also available in: Unified diff