0

We've discovered a strange new bug in a GWT application I'm maintaining, and I'm not sure when it became an issue. Possibly with a new Firefox version.

We're sending a POST request to the server using a FormPanel, essentially like many examples I've seen online. But since we actually want a PUT request, one of the hidden input parameters is named "method" and has a value of "put".

Now, when I look at the request in Fiddler coming from Firefox, it is being transformed into a GET request with all the parameters in the QueryString. In IE and Chrome, the parameters are in the body of a POST request.

I've displayed the value of FormPanel.getMethod() in an alert, and in IE and Chrome the string "post" is displayed, whereas in firefox it is showing "object HTMLInputElement". Unfortunately, hosted mode debugging does not work with this project.

It obviously looks like the FormPanel's getMethod() function is returning the hidden input parameter named method instead of the actual form's method in Firefox.

Technically I should avoid changing the servlet as this is from an OpenSource project that we use, though I've found I can fix the issue by changing the hidden input parameter's name to "_method" on both ends.

Has anyone ever seen anything like this? I can't find anything in Google.

UPDATE: We're using GWT 2.3 in case that helps

curtisvo
  • 43
  • 4

1 Answers1

0

Some insight can be found here Are the PUT, DELETE, HEAD, etc methods available in most web browsers? I would also suggest using XMLHttpRequest. In this case you [most probably] don't have to change anything on the server side.

In case if you use Submit button, you can write in its clickHandler function:

submitMyForm(yourTextBox.getText(), self); 
// self - is the instance of main class (named UploadForm here), needs to be passed here for future reference

and then some more (you can adapt this for your needs):

private native void submitMyForm(String text, UploadForm handler)/*-{
   var fd = new FormData();
   fd.append("textValue", text);

   var xhr = new XMLHttpRequest();
   var upload = xhr.upload;

   readyStateChangeHandler = function () {
      if (xhr.readyState == 4) {
         if (xhr.status == 200) {
           var serverResponse = eval(xhr.responseText); // optional               
           handler.@com.project.UploadForm::onUploadIsDone(Lcom/google/gwt/core/client/JavaScriptObject;)(serverResponse);
         } else {
           handler.@com.project.UploadForm::onUploadFailed(I)(status);
         }
      }
   };

   xhr.onreadystatechange = readyStateChangeHandler;
   xhr.open("PUT", yourActionUrlHere);
   xhr.send(formData);
}-*/;
Community
  • 1
  • 1
alexp
  • 787
  • 5
  • 26
  • If are used, onUploadIsDone() and onUploadFailed() have to be implemented in UploadForm class. – alexp Sep 19 '12 at 00:03