Mercurial > dive4elements > river
changeset 1490:15b4bc8eede0
#302 Improved input validation in WQ panels.
flys-client/trunk@3576 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 03 Jan 2012 13:27:14 +0000 |
parents | 03649eb8933a |
children | 2a00f4849738 |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java |
diffstat | 7 files changed, 63 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- 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 <ingo@intevation.de> + + 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 <felix.wolfsteller@intevation.de> Added and fixed translations of theme style properties.
--- 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();
--- 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
--- 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
--- 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
--- 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);
--- 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());