View Full Version : FormPanel submit JSON
29 Oct 2011, 3:03 PM
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?
Thanks in advance!
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.
31 Oct 2011, 6:44 AM
I was hoping for the equivalent functionality offered by ExtJs forms. I think I may try out your suggestion.
31 Oct 2011, 4:13 PM
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.
3 Nov 2011, 6:02 AM
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.
Thanks for your input once again!
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.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.