You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jd...@apache.org on 2009/04/07 21:26:34 UTC

svn commit: r762917 - /wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java

Author: jdonnerstag
Date: Tue Apr  7 19:26:34 2009
New Revision: 762917

URL: http://svn.apache.org/viewvc?rev=762917&view=rev
Log:
fixed WICKET-2174 Form#getMaxSize() -> no custom format
Issue: WICKET-2174

Modified:
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java?rev=762917&r1=762916&r2=762917&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java Tue Apr  7 19:26:34 2009
@@ -694,7 +694,7 @@
 
 	/**
 	 * Gets the maximum size for uploads. If null, the setting
-	 * {@link IApplicationSettings#getDefaultMaximumUploadSize()} is used.root.getJavascriptId()
+	 * {@link IApplicationSettings#getDefaultMaximumUploadSize()} is used.
 	 * 
 	 * @return the maximum size
 	 */
@@ -1624,31 +1624,13 @@
 				}
 
 				FileUploadException e = (FileUploadException)wre.getCause();
+
 				// Create model with exception and maximum size values
 				final Map<String, Object> model = new HashMap<String, Object>();
 				model.put("exception", e);
 				model.put("maxSize", getMaxSize());
 
-				if (e instanceof SizeLimitExceededException)
-				{
-					// Resource key should be <form-id>.uploadTooLarge to
-					// override default message
-					final String defaultValue = "Upload must be less than " + getMaxSize();
-					String msg = getString(getId() + "." + UPLOAD_TOO_LARGE_RESOURCE_KEY,
-						Model.ofMap(model), defaultValue);
-					error(msg);
-				}
-				else
-				{
-					// Resource key should be <form-id>.uploadFailed to override
-					// default message
-					final String defaultValue = "Upload failed: " + e.getLocalizedMessage();
-					String msg = getString(getId() + "." + UPLOAD_FAILED_RESOURCE_KEY,
-						Model.ofMap(model), defaultValue);
-					error(msg);
-
-					log.warn(msg, e);
-				}
+				onFileUploadException((FileUploadException)wre.getCause(), model);
 
 				// don't process the form if there is a FileUploadException
 				return false;
@@ -1658,6 +1640,41 @@
 	}
 
 	/**
+	 * The default message may look like ".. may not exceed 10240 Bytes..". Which is ok, but
+	 * sometimes you may want something like "10KB". By subclassing this method you may replace
+	 * maxSize in the model or add you own property and use that in your error message.
+	 * <p>
+	 * Don't forget to call super.onFileUploadException(e, model) at the end of your method.
+	 * 
+	 * @param e
+	 * @param model
+	 */
+	protected void onFileUploadException(final FileUploadException e,
+		final Map<String, Object> model)
+	{
+		if (e instanceof SizeLimitExceededException)
+		{
+			// Resource key should be <form-id>.uploadTooLarge to
+			// override default message
+			final String defaultValue = "Upload must be less than " + getMaxSize();
+			String msg = getString(getId() + "." + UPLOAD_TOO_LARGE_RESOURCE_KEY,
+				Model.ofMap(model), defaultValue);
+			error(msg);
+		}
+		else
+		{
+			// Resource key should be <form-id>.uploadFailed to override
+			// default message
+			final String defaultValue = "Upload failed: " + e.getLocalizedMessage();
+			String msg = getString(getId() + "." + UPLOAD_FAILED_RESOURCE_KEY, Model.ofMap(model),
+				defaultValue);
+			error(msg);
+
+			log.warn(msg, e);
+		}
+	}
+
+	/**
 	 * @see org.apache.wicket.Component#internalOnModelChanged()
 	 */
 	@Override