You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by andruhon <gi...@git.apache.org> on 2018/01/11 01:29:07 UTC

[GitHub] wicket pull request #255: Allow multipart submission of non modified FormDat...

GitHub user andruhon opened a pull request:

    https://github.com/apache/wicket/pull/255

    Allow multipart submission of non modified FormData with Wicket.Ajax

    Wicket is currently does fancy processing of the data and it's not possible to avoid it. This commit allows to submit non processed data, which should not be processed.
    
    This change, for example, will make possible to collect files from the drag and drop event and submit these files as FormData.
    
    A drop down handler example:
    ```JavaScript
            dropArea.addEventListener("drop", dropHandler);
            function dropHandler(ev) {            
                ev.preventDefault();
                Wicket.Log.info("DragAndDropFileUpload drop " + dropAreaId);
                var dt = ev.dataTransfer;
                var formData = new FormData();
                var files = [];
                var i;
                if (dt.items) {
                    // DataTransferItemList
                    for (i = 0; i < dt.items.length; i++) {
                        if (dt.items[i].kind == "file") {
                            var f = dt.items[i].getAsFile();
                            Wicket.Log.info("... file[" + i + "].name = " + f.name);
                            files.push(f);
                        }
                    }
                } else {
                    // DataTransfer
                    for (i = 0; i < dt.files.length; i++) {
                        Wicket.Log.info("... file[" + i + "].name = " + dt.files[i].name);
                        files.push(dt.files[i]);
                    }
                }
    
                if (files.length > 0) {
                    // formData.append(attrs['f']+"_hf_0","");
                    files.forEach(function (f) {
                        formData.append(fileUpload.getAttribute("name"), f)
                    });
    
                    // Wicket.Ajax.ajax will simply submit a multipart form into the iframe, which we don't want
                    // var xhr = new XMLHttpRequest();
                    // xhr.open('POST', attrs['u'] + "&wicket-ajax=true&wicket-ajax-baseurl=" + Wicket.Form.encode(Wicket.Ajax.baseUrl || '.'), true);
                    // xhr.send(formData);
                    // xhr.addEventListener("load", function() {console.log(arguments)})
                    Wicket.Ajax.ajax({
                        u: attrs.u,
                        m: 'POST',
                        mp: true,
                        npd: formData
                    });
    
                } else {
                    Wicket.Log.error("No files to upload " + dropAreaId);
                }
            }
    ```

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/andruhon/wicket master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/wicket/pull/255.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #255
    
----
commit be12e65d58619cb20ccc6750fe4655de4516d642
Author: Andrew Kondratev <an...@...>
Date:   2018-01-11T01:18:34Z

    Allow multipart submission of non modified FormData with Wicket.Ajax

----


---

[GitHub] wicket issue #255: Allow multipart submission of non modified FormData with ...

Posted by svenmeier <gi...@git.apache.org>.
Github user svenmeier commented on the issue:

    https://github.com/apache/wicket/pull/255
  
    Yes, this is what I came up with yesterday too.
    We have to support file inputs in forms too, for that I changed serializeInput() to handle "file" types.
    
    I'd like to drop support for the old iframe solution in submitMultipartForm(). I'll create an issue, let's see what other devs are thinking of this.


---

[GitHub] wicket issue #255: Allow multipart submission of non modified FormData with ...

Posted by andruhon <gi...@git.apache.org>.
Github user andruhon commented on the issue:

    https://github.com/apache/wicket/pull/255
  
    A little bit of demo showing what I was trying to achieve:
    https://github.com/andruhon/WicketDragAndDropFileAjaxUpload


---

[GitHub] wicket issue #255: Allow multipart submission of non modified FormData with ...

Posted by andruhon <gi...@git.apache.org>.
Github user andruhon commented on the issue:

    https://github.com/apache/wicket/pull/255
  
    @svenmeier I've tried a better approach without modifying the js function interface, it's just using multipart form data when possible, so works in IE9 as it used to work before.
    
    See it in the branch:
    https://github.com/andruhon/wicket/tree/try-multipart
    
    Also updated the demo to use this snapshot:
    https://github.com/andruhon/WicketDragAndDropFileAjaxUpload/tree/try-multipart
    tested in Chrome, FF, IE 11 and in emulated IE9-10
    
    If it looks like decent approach I can update my PR.


---

[GitHub] wicket pull request #255: Allow multipart submission of non modified FormDat...

Posted by andruhon <gi...@git.apache.org>.
Github user andruhon closed the pull request at:

    https://github.com/apache/wicket/pull/255


---

[GitHub] wicket issue #255: Allow multipart submission of non modified FormData with ...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on the issue:

    https://github.com/apache/wicket/pull/255
  
    Hi,
    
    is this PR reflection a subset of changes of: https://github.com/apache/wicket/pull/256?
    
    If yes we might consider to close this one and continue it in only one PR.
    
    Thanks a lot for your PR @andruhon 👍 


---

[GitHub] wicket issue #255: Allow multipart submission of non modified FormData with ...

Posted by andruhon <gi...@git.apache.org>.
Github user andruhon commented on the issue:

    https://github.com/apache/wicket/pull/255
  
    @svenmeier I would agree that this legacy workaround is not a good thing for Wicket 8. IE 9 share is averagely less than 1% nowdays and keeps dropping. Those who need a legacy support of IE 6 and 7 can use Wicket 6. Thank You. Just let me know If I can help you with this.


---

[GitHub] wicket issue #255: Allow multipart submission of non modified FormData with ...

Posted by svenmeier <gi...@git.apache.org>.
Github user svenmeier commented on the issue:

    https://github.com/apache/wicket/pull/255
  
    Many thanks!
    
    It seems you had to jump through a lot of hoops to make this work with Wicket's Ajax code - 
    maybe we can change it to make this easier.
    Why not drop the (old) iframe workaround and always use FormData for multipart requests?
    
    I'll give it a try this afternoon.


---

[GitHub] wicket issue #255: Allow multipart submission of non modified FormData with ...

Posted by andruhon <gi...@git.apache.org>.
Github user andruhon commented on the issue:

    https://github.com/apache/wicket/pull/255
  
    @svenmeier I'd say that submitMultipartForm could stay until the IE9 is closer to 0% in stats.


---