reiern70 commented on a change in pull request #466:
URL: https://github.com/apache/wicket/pull/466#discussion_r609562898
##########
File path:
wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
##########
@@ -47,6 +56,73 @@
{
private static final long serialVersionUID = 1L;
+ /**
+ * {@link org.apache.wicket.ajax.form.OnChangeAjaxBehavior} that
streams back to server properties
+ * of the selected file (at client side), even when file has not yet
being uploaded.
+s *
+ * @author Ernesto Reinaldo Barreiro ([email protected]).
+ */
+ public static abstract class OnFileSelectedBehavior extends
OnChangeAjaxBehavior
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void onBind() {
+ super.onBind();
+ Component component = getComponent();
+ if (!(component instanceof FileUploadField))
+ {
+ throw new WicketRuntimeException("Behavior " +
getClass().getName()
+ + " can only be added to an
instance of a FileUploadField");
+ }
+ }
+
+ @Override
+ protected void onUpdate(AjaxRequestTarget target)
+ {
+ Request request = RequestCycle.get().getRequest();
+ String fileName =
request.getRequestParameters().getParameterValue("fileName").toString();
+ Long fileSize =
request.getRequestParameters().getParameterValue("fileSize").toLong(0);
+ Date lastModified = new
Date(request.getRequestParameters().getParameterValue("lastModified").toLong(0));
+ String mimeType =
request.getRequestParameters().getParameterValue("type").toString();
+ onFileSelected(target, fileName, fileSize,
lastModified, mimeType);
+ }
+
+ /**
+ * Called when a file, at client side is selected.
+ *
+ * @param target The {@link
org.apache.wicket.ajax.AjaxRequestTarget}
+ * @param fileName The client file name
+ * @param fileSize The client file size
+ * @param lastModified The {@link java.util.Date} when file was
last modified.
+ * @param mimeType The MIME type of file.
+ */
+ protected abstract void onFileSelected(AjaxRequestTarget
target, String fileName, Long fileSize,
Review comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]