Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's what I ended up with that I believe works on all browsers:</p> <pre><code>form = new FormPanel(); form.setEncoding(FormPanel.ENCODING_MULTIPART); form.setMethod(FormPanel.METHOD_POST); form.add(new HTML("&lt;input type='file' id='fileselect' name='fileselect[]' multiple /&gt;")); </code></pre> <p>then on the server side I'm just using "org.apache.commons.fileupload" stuff.</p> <p>Yeah some people may not like the HTML element in the form, but here is how you CAN get the input element from it if you want:</p> <pre><code>protected Element getFileSelectElement() { HashMap&lt;String, Element&gt; idMap = Maps.newHashMap(); GuiUtil.parseIdsToMap(inputField.getElement(), idMap); Element input = idMap.get("fileselect"); return input; } public static void parseIdsToMap(Element element, HashMap&lt;String, Element&gt; idMap) { int nodeCount = element.getChildCount(); for (int i = 0; i &lt; nodeCount; i++) { Element e = (Element) element.getChild(i); if (e.getId() != null) { idMap.put(e.getId(), e); } } } </code></pre> <p>and finally... if you want to get access to the list of files the user selected, on the browser side, here's what I have:</p> <pre><code>public static native String getFileNames(Element input) /*-{ var ret = ""; //microsoft support if (typeof (input.files) == 'undefined' || typeof (input.files.length) == 'undefined') { return input.value; } for ( var i = 0; i &lt; input.files.length; i++) { if (i &gt; 0) { ret += ","; } ret += input.files[i].name; } return ret; }-*/; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload