You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2007/09/25 00:10:31 UTC
svn commit: r578993 - in
/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket:
markup/html/form/FormComponent.java util/convert/ConversionException.java
Author: ivaynberg
Date: Mon Sep 24 15:09:57 2007
New Revision: 578993
URL: http://svn.apache.org/viewvc?rev=578993&view=rev
Log:
WICKET-961: Add variables to ConversionException
Modified:
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/convert/ConversionException.java
Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java?rev=578993&r1=578992&r2=578993&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java Mon Sep 24 15:09:57 2007
@@ -1163,6 +1163,12 @@
error.setVariable("format", ((SimpleDateFormat)format).toLocalizedPattern());
}
+ Map variables = e.getVariables();
+ if (variables != null)
+ {
+ error.getVariables().putAll(variables);
+ }
+
error((IValidationError)error);
}
Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/convert/ConversionException.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/convert/ConversionException.java?rev=578993&r1=578992&r2=578993&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/convert/ConversionException.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/convert/ConversionException.java Mon Sep 24 15:09:57 2007
@@ -17,7 +17,9 @@
package org.apache.wicket.util.convert;
import java.text.Format;
+import java.util.HashMap;
import java.util.Locale;
+import java.util.Map;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.util.lang.Classes;
@@ -46,10 +48,13 @@
/** Target type for the failed conversion. */
private String targetTypeName;
-
+
/** Resource key for the message that should be displayed */
private String resourceKey;
+ /** Variable map to use in variable substitution */
+ private Map vars;
+
/**
* Construct exception with message.
*
@@ -225,5 +230,45 @@
return this;
}
+ /**
+ * Sets a variable that will be used in substitution
+ *
+ * @param name
+ * variable name
+ * @param value
+ * variable value
+ * @return this for chaining
+ */
+ public ConversionException setVariable(String name, Object value)
+ {
+ if (name == null || name.trim().length() == 0)
+ {
+ throw new IllegalArgumentException(
+ "Argument [[name]] cannot be null or an empty string");
+ }
+ if (value == null)
+ {
+ throw new IllegalArgumentException(
+ "Argument [[value]] cannot be null or an empty string");
+ }
+
+ if (vars == null)
+ {
+ vars = new HashMap(2);
+ }
+ vars.put(name, value);
+
+ return this;
+ }
+
+ /**
+ * Returns the map of variables for this exception.
+ *
+ * @return map of variables for this exception (or null if no variables were defined)
+ */
+ public Map getVariables()
+ {
+ return vars;
+ }
}