Mercurial > dive4elements > gnv-client
changeset 663:9a019c125b60
Improved error handling when changing chart/histogram options.
gnv/trunk@755 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 09 Mar 2010 15:18:11 +0000 (2010-03-09) |
parents | 5f5f273c8566 |
children | 15497dce8fcd |
files | gnv/ChangeLog gnv/src/main/java/de/intevation/gnv/action/ChangeOptionsAction.java gnv/src/main/java/de/intevation/gnv/action/CommunicationKeys.java gnv/src/main/resources/applicationMessages.properties gnv/src/main/resources/applicationMessages_en.properties gnv/src/main/webapp/WEB-INF/jsp/includes/display_diagramm_options_inc.jsp gnv/src/main/webapp/WEB-INF/jsp/includes/display_histogram_options_inc.jsp gnv/src/main/webapp/styles/default.css |
diffstat | 8 files changed, 156 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv/ChangeLog Mon Mar 08 17:09:28 2010 +0000 +++ b/gnv/ChangeLog Tue Mar 09 15:18:11 2010 +0000 @@ -1,3 +1,28 @@ +2010-03-09 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + * src/main/java/de/intevation/gnv/action/ChangeOptionsAction.java: Parse + user input from chart/histogram options panel and check if integer and + doubles are valid - if we find a value which is not valid for the + configured type, we set an exception message which is displayed in the + chart/histogram options panel and sets the corresponding parameter to its + default value. + + * src/main/webapp/WEB-INF/jsp/includes/display_histogram_options_inc.jsp, + src/main/webapp/WEB-INF/jsp/includes/display_diagramm_options_inc.jsp: + Display error message in options panel if there is one. + + * src/main/resources/applicationMessages_en.properties, + src/main/resources/applicationMessages.properties: + Added strings to display error messages when the user entered a bad + formatted number in chart/histogram options panel. + + * src/main/java/de/intevation/gnv/action/CommunicationKeys.java: Added two + further error message keys used to store error messages for + chart/histogram options. + + * src/main/webapp/styles/default.css: Added a new class 'chartException' to + adjust the style of an error message in chart/histogram options panel. + 2010-03-08 Ingo Weinzierl <ingo.weinzierl@intevation.de> * src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java:
--- a/gnv/src/main/java/de/intevation/gnv/action/ChangeOptionsAction.java Mon Mar 08 17:09:28 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/ChangeOptionsAction.java Tue Mar 09 15:18:11 2010 +0000 @@ -1,7 +1,10 @@ package de.intevation.gnv.action; +import java.text.NumberFormat; +import java.text.ParseException; import java.util.Collection; import java.util.Iterator; +import java.util.Locale; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -18,6 +21,8 @@ import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription; import de.intevation.gnv.artifactdatabase.objects.OutputMode; import de.intevation.gnv.artifactdatabase.objects.OutputParameter; +import de.intevation.gnv.propertiesreader.PropertiesReaderFactory; +import de.intevation.gnv.propertiesreader.PropertiesReader; /** * @author Tim Englich <tim.englich@intevation.de> @@ -42,6 +47,8 @@ HttpServletResponse response) throws Exception { log.debug("NextArtifactStepAction.execute"); try { + PropertiesReaderFactory fac = PropertiesReaderFactory.getInstance(); + PropertiesReader reader = fac.getPropertiesReader(); SessionModel sm = SessionModelFactory.getInstance() .getSessionModel(request); @@ -58,17 +65,66 @@ DiagrammOptions diagrammOptions = new DiagrammOptions(); while (it.hasNext()) { OutputParameter parameter = it.next(); - String value = request.getParameter(parameter.getName()); - if (parameter.getType().equalsIgnoreCase("boolean")){ + String name = parameter.getName(); + String old = parameter.getValue(); + String value = request.getParameter(name); + String type = parameter.getType(); + + if (log.isDebugEnabled()) { + log.debug("Change chart options now..."); + log.debug("Parameter name: " + name); + log.debug("Parameter type: " + type); + log.debug("Parameter value: " + value); + } + + if (type.equalsIgnoreCase("boolean")){ if (value == null){ value = "false"; } else { value = "true"; } + + diagrammOptions.setValue(name,value); } - diagrammOptions.setValue(parameter.getName(),value); + else if (type.equalsIgnoreCase("integer")) { + if (validInteger(request.getLocale(), value)) { + diagrammOptions.setValue(name, value); + } + else { + log.warn("Text is not a valid integer: "+value); + diagrammOptions.setValue(name, old); + request.setAttribute( + CommunicationKeys.REQUEST_EXCEPTION_MESSAGE, + "input.not.a.integer" + ); + + request.setAttribute( + CommunicationKeys.REQUEST_EXCEPTION_VALUE, + value + ); + } + } + else if (type.equalsIgnoreCase("double")) { + if (validDouble(request.getLocale(), value)) { + diagrammOptions.setValue(name, value); + } + else { + log.warn("Text is not a valid double: "+value); + diagrammOptions.setValue(name, old); + + request.setAttribute( + CommunicationKeys.REQUEST_EXCEPTION_MESSAGE, + "input.not.a.double" + ); + + request.setAttribute( + CommunicationKeys.REQUEST_EXCEPTION_VALUE, + value + ); + } + } } sm.setDiagrammOptions(diagrammOptions); @@ -101,5 +157,40 @@ } } + protected boolean validInteger(Locale locale, String value) { + try { + if (value.split("\\.").length > 1 || value.split("\\,").length > 1){ + return false; + } + + NumberFormat format = NumberFormat.getIntegerInstance(locale); + format.setParseIntegerOnly(true); + Number number = format.parse(value); + + if (number.longValue() < 0) + return false; + + return (number instanceof Integer) || (number instanceof Long); + } + catch (ParseException pe) { + return false; + } + } + + + protected boolean validDouble(Locale locale, String value) { + try { + NumberFormat format = NumberFormat.getInstance(locale); + Number number = format.parse(value); + + if (number.doubleValue() < 0) + return false; + + return (number instanceof Double) || validInteger(locale, value); + } + catch (ParseException pe) { + return false; + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/gnv/src/main/java/de/intevation/gnv/action/CommunicationKeys.java Mon Mar 08 17:09:28 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/CommunicationKeys.java Tue Mar 09 15:18:11 2010 +0000 @@ -9,5 +9,7 @@ /** * The Key which should be used for accessing ExceptionMessages */ - public final static String REQUEST_EXCEPTION_MESSAGE_ID = "request_exception_message"; + public final static String REQUEST_EXCEPTION_MESSAGE_ID = "request_exception_message_id"; + public final static String REQUEST_EXCEPTION_MESSAGE = "request_exception_message"; + public final static String REQUEST_EXCEPTION_VALUE = "request_exception_value"; }
--- a/gnv/src/main/resources/applicationMessages.properties Mon Mar 08 17:09:28 2010 +0000 +++ b/gnv/src/main/resources/applicationMessages.properties Tue Mar 09 15:18:11 2010 +0000 @@ -95,4 +95,6 @@ de.intevation.gnv.geobackend.base.query.exception.queryexception..java.sql.sqlexception =Es ist ein interner Serverfehler aufgetreten. Bitte benachrichtigen Sie den Support. java.io.ioexception..the.server.encountered.an.unexpected.condition.which.prevented.it.from.fulfilling.the.request=Es ist ein interner Serverfehler aufgetreten. Bitte benachrichtigen Sie den Support. java.lang.illegalargumentexception..inputstream.cannot.be.null=Es ist ein interner Serverfehler aufgetreten. Bitte benachrichtigen Sie den Support. - +input.is.not.valid.for.this.state=Der von Ihnen eingegebene Wert ist ung\u00fcltig. Bitte versuchen Sie es erneut. +input.not.a.integer= ist keine g\u00fcltige Ganzzahl. Bitte versuchen Sie es erneut. +input.not.a.double= ist keine g\u00fcltige Flie\u00dfkommazahl. Bitte versuchen Sie es erneut.
--- a/gnv/src/main/resources/applicationMessages_en.properties Mon Mar 08 17:09:28 2010 +0000 +++ b/gnv/src/main/resources/applicationMessages_en.properties Tue Mar 09 15:18:11 2010 +0000 @@ -93,3 +93,6 @@ de.intevation.gnv.geobackend.base.query.exception.queryexception..java.sql.sqlexception: A internal Server error has occurred. Please contact the Support. java.io.ioexception..the.server.encountered.an.unexpected.condition.which.prevented.it.from.fulfilling.the.request = A internal Server error has occurred. Please contact the Support. java.lang.illegalargumentexception..inputstream.cannot.be.null = A internal Server error has occurred. Please contact the Support. +input.is.not.valid.for.this.state=You entered an invalid value. Please try again. +input.not.a.integer= is not a valid integer. Please try again. +input.not.a.double= is not a valid floating-point number. Please try again.
--- a/gnv/src/main/webapp/WEB-INF/jsp/includes/display_diagramm_options_inc.jsp Mon Mar 08 17:09:28 2010 +0000 +++ b/gnv/src/main/webapp/WEB-INF/jsp/includes/display_diagramm_options_inc.jsp Tue Mar 09 15:18:11 2010 +0000 @@ -1,5 +1,6 @@ <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %> <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean-el" prefix="bean-el" %> +<%@page import="de.intevation.gnv.action.CommunicationKeys"%> <%@page import="de.intevation.gnv.action.sessionmodel.DiagrammOptions"%> <%@page import="de.intevation.gnv.action.sessionmodel.SessionModelFactory"%> <%@page import="de.intevation.gnv.artifactdatabase.objects.OutputMode"%> @@ -9,7 +10,9 @@ <%@page import="java.util.Collection"%> <%@page import="java.util.Iterator"%> <%@page import="java.net.URLEncoder"%> -<% +<% + String exceptionMsg = (String)request.getAttribute(CommunicationKeys.REQUEST_EXCEPTION_MESSAGE); + String exceptionValue = (String)request.getAttribute(CommunicationKeys.REQUEST_EXCEPTION_VALUE); String target = "chart"; String targetPDF = "pdf"; String targetSVG = "svg"; @@ -55,6 +58,13 @@ <legend onmousedown="displayDiv('diagramOptionsContent');" class="expandableFieldset"> <bean:message key="gnviewer.diagram.options.header.title"/> </legend> + + <% if (exceptionMsg != null) {%> + <div id="chartException" class="chartException"> + '<%=exceptionValue%>' <bean-el:message key="<%=exceptionMsg%>"/> + </div> + <%}%> + <form id="outputOptionsForm" method="post" action="<%=response.encodeURL("changeOptions.do")%>"> <table> <%if (outputMode != null && outputMode.getOutputParameters() != null && !outputMode.getOutputParameters().isEmpty()){
--- a/gnv/src/main/webapp/WEB-INF/jsp/includes/display_histogram_options_inc.jsp Mon Mar 08 17:09:28 2010 +0000 +++ b/gnv/src/main/webapp/WEB-INF/jsp/includes/display_histogram_options_inc.jsp Tue Mar 09 15:18:11 2010 +0000 @@ -1,5 +1,6 @@ <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %> <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean-el" prefix="bean-el" %> +<%@page import="de.intevation.gnv.action.CommunicationKeys"%> <%@page import="de.intevation.gnv.action.sessionmodel.DiagrammOptions"%> <%@page import="de.intevation.gnv.action.sessionmodel.SessionModelFactory"%> <%@page import="de.intevation.gnv.artifactdatabase.objects.OutputMode"%> @@ -10,6 +11,8 @@ <%@page import="java.util.Iterator"%> <%@page import="java.net.URLEncoder"%> <% + String exceptionMsg = (String)request.getAttribute(CommunicationKeys.REQUEST_EXCEPTION_MESSAGE); + String exceptionValue = (String)request.getAttribute(CommunicationKeys.REQUEST_EXCEPTION_VALUE); String target = "histogram"; String targetPDF = "pdf"; String targetSVG = "svg"; @@ -54,6 +57,13 @@ <legend onmousedown="displayDiv('histogramOptionsContent');" class="expandableFieldset"> <bean:message key="gnviewer.histogram.options.header.title"/> </legend> + + <% if (exceptionMsg != null) {%> + <div id="chartException" class="chartException"> + '<%=exceptionValue%>' <bean-el:message key="<%=exceptionMsg%>"/> + </div> + <%}%> + <form id="outputOptionsForm" method="post" action="<%=response.encodeURL("changeOptions.do?target="+target)%>"> <table> <%if (outputMode != null && outputMode.getOutputParameters() != null && !outputMode.getOutputParameters().isEmpty()){
--- a/gnv/src/main/webapp/styles/default.css Mon Mar 08 17:09:28 2010 +0000 +++ b/gnv/src/main/webapp/styles/default.css Tue Mar 09 15:18:11 2010 +0000 @@ -170,6 +170,13 @@ font-weight: bold; } +.chartException { + color: red; + font-size: 10px; + font-weight: bold; + margin: 2px 2px; +} + /* ====================== Header ============================= */ #head {