# HG changeset patch # User Ingo Weinzierl # Date 1325597234 0 # Node ID 15b4bc8eede0dfdca24c9e33a28aafa8c3816dd6 # Parent 03649eb8933a24dafecfad02297bfd220abac244 #302 Improved input validation in WQ panels. flys-client/trunk@3576 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 03649eb8933a -r 15b4bc8eede0 flys-client/ChangeLog --- a/flys-client/ChangeLog Tue Jan 03 09:47:36 2012 +0000 +++ b/flys-client/ChangeLog Tue Jan 03 13:27:14 2012 +0000 @@ -1,3 +1,22 @@ +2012-01-02 Ingo Weinzierl + + flys/issue302 (Uncaught exception wenn bei Wasserspiegellage-Berechnung kein W/Q angegeben wird) + + * src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java: + Catch a NumberFormatException in validateForm() and return in such cases + false for an invalid DoubleRangePanel. + + * src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java: Catch + NullPointerExceptions when fetching from, to and step values from + DoubleRangePanel. Use DoubleRangePanel.validateForm() (with no parameters) + to validate the DoubleRangePanel correctly. + + * src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants.java, + src/main/java/de/intevation/flys/client/client/FLYSConstants.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties: + Added errors/warnings. + 2012-01-02 Felix Wolfsteller Added and fixed translations of theme style properties. diff -r 03649eb8933a -r 15b4bc8eede0 flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Tue Jan 03 09:47:36 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Tue Jan 03 13:27:14 2012 +0000 @@ -202,6 +202,10 @@ String wrongFormat(); + String atLeastOneValue(); + + String missingInput(); + String too_many_values (); String description(); diff -r 03649eb8933a -r 15b4bc8eede0 flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Tue Jan 03 09:47:36 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Tue Jan 03 13:27:14 2012 +0000 @@ -109,6 +109,8 @@ unitDiffInM = Diff [m]: unitLocation = km wrongFormat = Wrong format +atLeastOneValue = You need to insert at least one value. +missingInput = You need to enter a value. too_many_values = Only one value allowed description = Description diff -r 03649eb8933a -r 15b4bc8eede0 flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Tue Jan 03 09:47:36 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Tue Jan 03 13:27:14 2012 +0000 @@ -109,6 +109,8 @@ unitDiffInM = Diff [m]: unitLocation = km wrongFormat = Falsches Format +atLeastOneValue = Sie m\u00fcssen mindestens einen Wert eingeben. +missingInput = Sie m\u00fcssen einen Wert eingeben. too_many_values = Nur ein Eingabewert erlaubt description = Beschreibung diff -r 03649eb8933a -r 15b4bc8eede0 flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Tue Jan 03 09:47:36 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Tue Jan 03 13:27:14 2012 +0000 @@ -109,6 +109,8 @@ unitDiffInM = Diff [m]: unitLocation = km wrongFormat = Wrong format +atLeastOneValue = You need to insert at least one value. +missingInput = You need to enter a value. too_many_values = Only one value allowed description = Description diff -r 03649eb8933a -r 15b4bc8eede0 flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java Tue Jan 03 09:47:36 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java Tue Jan 03 13:27:14 2012 +0000 @@ -148,10 +148,15 @@ public boolean validateForm() { - return - validateForm(fromItem) && - validateForm(toItem) && - validateForm(stepItem); + try { + return + validateForm(fromItem) && + validateForm(toItem) && + validateForm(stepItem); + } + catch (NumberFormatException nfe) { + return false; + } } /** @@ -215,7 +220,7 @@ * * @return the start value. */ - public double getFrom() { + public double getFrom() throws NullPointerException { String v = getValueAsString(FIELD_FROM); return getDouble(v); @@ -227,7 +232,7 @@ * * @return the end value. */ - public double getTo() { + public double getTo() throws NullPointerException { String v = getValueAsString(FIELD_TO); return getDouble(v); @@ -239,7 +244,7 @@ * * @return the step width. */ - public double getStep() { + public double getStep() throws NullPointerException { String v = getValueAsString(FIELD_WIDTH); return getDouble(v); diff -r 03649eb8933a -r 15b4bc8eede0 flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java Tue Jan 03 09:47:36 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java Tue Jan 03 13:27:14 2012 +0000 @@ -729,9 +729,19 @@ errors.add(MESSAGE.wrongFormat()); } - double from = panel.getFrom(); - double to = panel.getTo(); - double step = panel.getStep(); + double from; + double to; + double step; + + try { + from = panel.getFrom(); + to = panel.getTo(); + step = panel.getStep(); + } + catch (NullPointerException npe) { + errors.add(MESSAGE.missingInput()); + return errors; + } if (from < min || from > max) { String tmp = MESSAGE.error_validate_lower_range(); @@ -769,6 +779,12 @@ } double[] values = panel.getInputValues(); + + if (values == null || values.length == 0) { + errors.add(MESSAGE.atLeastOneValue()); + return errors; + } + double[] good = new double[values.length]; int idx = 0; @@ -1412,7 +1428,7 @@ protected void saveRangeWValue(DoubleRangePanel p, FormItem item) { - if (p.validateForm(item)) { + if (p.validateForm()) { setFromW(p.getFrom()); setToW(p.getTo()); setStepW(p.getStep()); @@ -1421,7 +1437,7 @@ protected void saveRangeQValue(DoubleRangePanel p, FormItem item) { - if (p.validateForm(item)) { + if (p.validateForm()) { setFromQ(p.getFrom()); setToQ(p.getTo()); setStepQ(p.getStep()); @@ -1430,7 +1446,7 @@ protected void saveRangeQFreeValue(DoubleRangePanel p, FormItem item) { - if (p.validateForm(item)) { + if (p.validateForm()) { setFromQFree(p.getFrom()); setToQFree(p.getTo()); setStepQFree(p.getStep());