View Full Version : Feature Request : Way to return binary data via POST

8 Feb 2010, 6:24 AM
I am not a Premium member so i can not post this in the Feature Requests...

I have been struggling with returning HTTP POST data from a Form. I am using the FormPanel and POSTing the data to a servlet fine. the issue is, the result from my Servlet is a PDF, not simple HTML, XML, JSON....parsable data.

It would make sense for the API to support the return of binary type data...when i call form.submit() i should be able to simply have the browser render the result into my ContentPanel or Container just like when using a HTTP GET.

8 Feb 2010, 8:31 AM
Well, you have 2 options.

First, make your servlet return an URL and set this URL in a IFRAME or something.

Or, you could make your servlet return your data encoded(i.e. base64) and set in a IFRAME a data URI.

Take a look at: http://en.wikipedia.org/wiki/Data_URI_scheme

I think that the last one is what you need.


8 Feb 2010, 8:39 AM
thanks for the response. The only way i could get things to work is to POST to my PDF generator, store the data in the HttpSession, and then do a get to pull back the PDF. This is not a good solution as i have to use HttpSession. And i have to keep all the data in HttpSession because any resizing of the Window forces a re-query of the URL

If i was just using something like JSP i would simply have my FORM do a POST and return the PDF. Is there a way to have the form target a new browser window?

The DataURI stuff is cool, however it has very limited browser support. I have to support down to IE 6

8 Feb 2010, 8:42 AM
Yes, you can target a form.


8 Feb 2010, 8:45 AM
How do you do that in GXT? There is no setTarget( String target ) operation on a FormPanel

8 Feb 2010, 8:57 AM
The setTarget method is marked as private.
Try to extend the class and then you can set the value you want.


8 Feb 2010, 9:26 AM
FYI, you will need to use JSNI to access this method, as it's private, overriding don't let you access it.

8 Feb 2010, 12:09 PM
i tried extending FormPanel and overriding the getTarget() method but it never gets called. I basically gave up and got a hack to work. I am really hoping the API is updated in a future rev to make this easy to do.

Basically i pop up a window with a FormPanel in it which gets dynamically filled with HiddenFields based on user selections in a grid. I POST this form to a Servlet which loads the data into the HttpSession (bad design but have to do it to make this work), then upon getting the result back from that POST, i open a new browser window and do a HTTP GET on my reporting Servlet which uses the data in the users Session to build the report.

It would be nice for the API to let me POST to a URL and simply have the response dumped into the Form's container. then i could avoid using the HttpSession which is a good thing.

8 Feb 2010, 12:44 PM
Ok, here is your code.

import com.extjs.gxt.ui.client.widget.form.FormPanel;

* @author Tercio F. Gaudencio Filho
public class MyFormPanel extends FormPanel
public native void setTarget(String target)/*-{

10 Feb 2010, 9:39 AM
here is a solution for a download with example code:

Grid: Adding download file