comparison flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java @ 1507:c21d14e48040

Improved validation and property handling. flys-client/trunk@3645 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 11 Jan 2012 10:21:22 +0000
parents 339f8aa641b5
children 4f4d29404dba
comparison
equal deleted inserted replaced
1506:339f8aa641b5 1507:c21d14e48040
1 package de.intevation.flys.client.client.utils; 1 package de.intevation.flys.client.client.utils;
2 2
3 import java.util.Map; 3 import java.util.Map;
4 4
5 import com.google.gwt.core.client.GWT;
5 import com.google.gwt.i18n.client.NumberFormat; 6 import com.google.gwt.i18n.client.NumberFormat;
6 7
7 import com.smartgwt.client.widgets.form.fields.FormItem; 8 import com.smartgwt.client.widgets.form.fields.FormItem;
8 9
10 import de.intevation.flys.client.client.FLYSConstants;
11
9 /** 12 /**
10 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 13 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
11 */ 14 */
12 public class DoubleValidator extends Validator { 15 public class DoubleValidator implements Validator {
16
17 /** The interface that provides i18n messages. */
18 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
13 19
14 /** 20 /**
15 * 21 *
16 */ 22 */
17 @Override 23 public boolean validate(FormItem item, Map errors) {
18 protected boolean validate(FormItem item, Map errors) {
19 boolean valid = true; 24 boolean valid = true;
20 25
21 String v = (String) item.getValue(); 26 String v = item.getValue().toString();
22 27
23 NumberFormat f = NumberFormat.getDecimalFormat(); 28 NumberFormat f = NumberFormat.getDecimalFormat();
24 29
25 try { 30 try {
26 if (v == null) { 31 if (v == null) {
38 43
39 valid = false; 44 valid = false;
40 } 45 }
41 return valid; 46 return valid;
42 } 47 }
43
44
45 public String toProtocolString(FormItem item, Map errors) {
46 if(validate(item, errors)) {
47 return item.getValue().toString().replaceAll(",", ".");
48 }
49 else {
50 return null;
51 }
52 }
53 } 48 }
54 49

http://dive4elements.wald.intevation.org