reiern70 commented on a change in pull request #467:
URL: https://github.com/apache/wicket/pull/467#discussion_r610424557
##########
File path:
wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
##########
@@ -47,6 +59,146 @@
{
private static final long serialVersionUID = 1L;
+ /**
+ * Description of file properties as in browser client side.
+ */
+ public static class FileDescription implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final String fileName;
+ private final long fileSize;
+ private final Date lastModified;
+ private final String mimeType;
+
+ public FileDescription(String fileName, long fileSize, long
lastModified, String mimeType) {
+ this.fileName = fileName;
+ this.fileSize = fileSize;
+ this.lastModified = new Date(lastModified);
+ this.mimeType = mimeType;
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public long getFileSize() {
+ return fileSize;
+ }
+
+ public Date getLastModified() {
+ return lastModified;
+ }
+
+ public String getMimeType() {
+ return mimeType;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return
false;
+ FileDescription that = (FileDescription) o;
+ return fileName.equals(that.fileName);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fileName);
+ }
+ }
+
+ /**
+ * {@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();
+ List<FileDescription> fileDescriptions = new
ArrayList<>();
+ IRequestParameters parameters =
request.getRequestParameters();
+ String[] fileNames =
parse(parameters.getParameterValue("fileName"));
Review comment:
To myself: can we use getParameterValues instead?
--
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]