I am wondering if there is a way to configure a FormPanel's submit() to send a content-type other than application/x-www-form-urlencoded. I know ExtJs allows you to change the type of submission the forms make, but can we somehow set a FormPanel to submit a Content-Type of application/json and change the default accept header as well?
We have nothing implement this for. You could could subclass FormPanel and change the behaviour. Basicly you would create the json string on your on, put it into a hidden field and submit only that one.
We have nothing implement this for. You could could subclass FormPanel and change the behaviour. Basicly you would create the json string on your on, put it into a hidden field and submit only that one.
I'm fairly certain that even ExtJS only supports that functionality when doing a AJAX post, not a standard form post. Html forms only have a few formats they support, and JSON is not one of them.
To make a custom AJAX call, the GWT class RequestBuilder is used.
Take the model bound to your form, pass it through JsonConverter.encode to get a JSONObject, and call toString() on that to get the json data. This can be sent to the server in any way you choose, including via RequestBuilder. HttpProxy can be instructed to use this: Override HttpProxy.generateUrl to serialize to JSON as described above, and make sure the standard RequestBuilder given is told to use POST as the method.
Yes, you are correct about ExtJs AJAX posts but the feature I was speaking to was the ability to pass the jsonData config. Anyway, I did almost exactly as you suggested with RequestBuilder except I extended FormPanel and overrode submit utilizing RequestBuilder. This is an acceptable solution as I get the benefits of FormPanel mixed with REST calls.
If you are not using a normal form submit, you should not use a FormPanel at all, as this one adds an extra overhead which you not require in that case.