Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java @ 1504:02a9104c0451
Implemented the validators more object oriented.
flys-client/trunk@3634 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Mon, 09 Jan 2012 17:29:56 +0000 |
parents | |
children | 339f8aa641b5 |
comparison
equal
deleted
inserted
replaced
1503:3304608baf35 | 1504:02a9104c0451 |
---|---|
1 package de.intevation.flys.client.client.utils; | |
2 | |
3 import java.util.Map; | |
4 | |
5 import com.google.gwt.i18n.client.NumberFormat; | |
6 | |
7 import com.smartgwt.client.widgets.form.fields.FormItem; | |
8 | |
9 /** | |
10 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
11 */ | |
12 public class DoubleValidator extends Validator { | |
13 | |
14 /** | |
15 * | |
16 */ | |
17 @Override | |
18 protected boolean validate(FormItem item, Map errors) { | |
19 boolean valid = true; | |
20 | |
21 String v = (String) item.getValue(); | |
22 | |
23 NumberFormat f = NumberFormat.getDecimalFormat(); | |
24 | |
25 try { | |
26 if (v == null) { | |
27 throw new NumberFormatException("empty"); | |
28 } | |
29 | |
30 double value = f.parse(v); | |
31 | |
32 errors.remove(item.getFieldName()); | |
33 } | |
34 catch (NumberFormatException nfe) { | |
35 errors.put(item.getFieldName(), MSG.wrongFormat()); | |
36 | |
37 item.focusInItem(); | |
38 | |
39 valid = false; | |
40 } | |
41 return valid; | |
42 } | |
43 } | |
44 |