martin-g commented on a change in pull request #467:
URL: https://github.com/apache/wicket/pull/467#discussion_r609576034



##########
File path: 
wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
##########
@@ -47,6 +57,74 @@
 {
        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();
+                       IRequestParameters parameters = 
request.getRequestParameters();
+                       String fileName = 
parameters.getParameterValue("fileName").toString();
+                       long fileSize = 
parameters.getParameterValue("fileSize").toLong(0);
+                       Date lastModified = new 
Date(parameters.getParameterValue("lastModified").toLong(0));
+                       String mimeType = 
parameters.getParameterValue("mimeType").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:
       I think we should think about the `multiple` support now, because later 
this method signature may need to be changed to something like `protected 
abstract void onFilesSelected(AjaxRequestTarget target, List<FileDescription>)`




-- 
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]


Reply via email to