Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/client/utils/IntegerValidator.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 | c21d14e48040 |
rev | line source |
---|---|
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.client.client.utils; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
2 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
3 import java.util.Map; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
4 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
5 import com.smartgwt.client.widgets.form.fields.FormItem; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
6 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
7 /** |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
8 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
9 */ |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
10 public class IntegerValidator extends Validator { |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
11 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
12 /** |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
13 * |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
14 */ |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
15 @Override |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
16 protected boolean validate(FormItem item, Map errors) { |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
17 boolean valid = true; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
18 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
19 String v = (String) item.getValue(); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
20 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
21 try { |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
22 if (v == null) { |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
23 throw new NumberFormatException("empty"); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
24 } |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
25 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
26 int value = Integer.parseInt(v); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
27 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
28 errors.remove(item.getFieldName()); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
29 } |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
30 catch (NumberFormatException nfe) { |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
31 errors.put(item.getFieldName(), MSG.wrongFormat()); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
32 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
33 item.focusInItem(); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
34 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
35 valid = false; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
36 } |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
37 return valid; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
38 } |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
39 } |