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



##########
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 (reier...@gmail.com).
+        */
+       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();

Review comment:
       nitpick: cache `request.getRequestParameters()` as a local variable

##########
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 (reier...@gmail.com).
+        */
+       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:
       s/Long/long/

##########
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 (reier...@gmail.com).
+        */
+       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);

Review comment:
       s/Long/long/

##########
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 (reier...@gmail.com).
+        */
+       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,
+                                                                               
           Date lastModified, String mimeType);
+
+               @Override
+               protected void updateAjaxAttributes(AjaxRequestAttributes 
attributes) {
+                       super.updateAjaxAttributes(attributes);
+                       attributes.getAjaxCallListeners().add(new 
IAjaxCallListener()
+                       {
+                               @Override
+                               public CharSequence getPrecondition(Component 
component)
+                               {
+                                       return "if (this.files) {  
window."+component.getMarkupId()+"_file = this.files[0]; return true; } " +
+                                                       "else return false;";
+                               }
+                       });
+
+                       String var = 
"window."+getComponent().getMarkupId()+"_file";

Review comment:
       Does this compile in Java11 ? 
   `var` is a keyword in Java 10+. I think you will need to rename it.




-- 
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:
us...@infra.apache.org


Reply via email to