diff flys-client/src/main/java/de/intevation/flys/client/client/utils/Validator.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 2a8b5dcbe8ca
children c21d14e48040
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/utils/Validator.java	Mon Jan 09 17:07:17 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/utils/Validator.java	Mon Jan 09 17:29:56 2012 +0000
@@ -1,11 +1,14 @@
 package de.intevation.flys.client.client.utils;
+
+import java.util.Map;
+
 import com.google.gwt.core.client.GWT;
+
 import com.smartgwt.client.widgets.form.DynamicForm;
 import com.smartgwt.client.widgets.form.fields.FormItem;
-import com.google.gwt.i18n.client.NumberFormat;
 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
-import java.util.Map;
+
 import de.intevation.flys.client.client.FLYSConstants;
 
 /**
@@ -33,77 +36,13 @@
         Map errors = form.getErrors();
         String type = item.getAttribute("internalType");
 
-        if(type.equals("double")) {
-            validateFloat(item, errors);
-            form.setErrors(errors, true);
-        }
-        else if(type.equals("integer")) {
-            validateInteger(item, errors);
-            form.setErrors(errors, true);
-        }
-        else {
-            GWT.log("No Attribute 'internalType' set. Not using any validator.");
-        }
+        validate(item, errors);
+        form.setErrors(errors, true);
     }
 
 
-    /**
-     *
-     */
-    protected boolean validateInteger(FormItem item, Map errors) {
-        boolean valid = true;
-
-        String v = (String) item.getValue();
-
-        NumberFormat f = NumberFormat.getDecimalFormat();
-
-        try {
-            if (v == null) {
-                throw new NumberFormatException("empty");
-            }
-
-            int value = Integer.parseInt(v);
-
-            errors.remove(item.getFieldName());
-        }
-        catch (NumberFormatException nfe) {
-            errors.put(item.getFieldName(), MSG.wrongFormat());
-
-            item.focusInItem();
-
-            valid = false;
-        }
-        return valid;
-    }
-
-
-    /**
-     *
-     */
-    protected boolean validateFloat(FormItem item, Map errors) {
-        boolean valid = true;
-
-        String v = (String) item.getValue();
-
-        NumberFormat f = NumberFormat.getDecimalFormat();
-
-        try {
-            if (v == null) {
-                throw new NumberFormatException("empty");
-            }
-
-            double value = f.parse(v);
-
-            errors.remove(item.getFieldName());
-        }
-        catch (NumberFormatException nfe) {
-            errors.put(item.getFieldName(), MSG.wrongFormat());
-
-            item.focusInItem();
-
-            valid = false;
-        }
-        return valid;
+    protected boolean validate(FormItem item, Map errors) {
+        return true;
     }
 }
 

http://dive4elements.wald.intevation.org