I want to ask if there is a "Save As" dialog in Ext Js Modern? So I can save an Object from a web Page into a local file.

- 296
- 1
- 8
- 23
-
You couldn't spend 5s of your time typing "extjs dialog" into google? https://docs.sencha.com/extjs/6.5.0/modern/Ext.Dialog.html. Your other question has also been answered in multiple places already – Dominic Oct 22 '18 at 12:56
-
This is not what I need!! I am enough good in Sencha and this dialog is not as what described in the question!!!! I don't think that it is implemented in the Ext Js. but may be someone else has done that... – Hasan Oct 22 '18 at 12:58
-
What do you need in the Save As? Dialog can have text and buttons, or you can have something with less config with e.g. https://docs.sencha.com/ext/6.5.1/classic/Ext.MessageBox.html. You have to of course do the saving logic yourself. – Dominic Oct 22 '18 at 13:23
-
I emailed Sencha and they have told that they do not have a save as component. They gave me other solution which depends on the browser itself. it is also not what I am looking for. therefore I will try to find a better solution and I will post it when it is ready – Hasan Oct 22 '18 at 13:34
-
It's quite widely supported to create a Blob url and the "download" attribute on anchor tags, I would try them in combination. Or File API but I think that would have less support. – Dominic Oct 22 '18 at 14:19
2 Answers
One Solution (Depends on the Web Browser and is not supported by all browsers!) is using Mozilla API (File and BLOB) like in: https://developer.mozilla.org/en-US/docs/Web/API/File/File and https://developer.mozilla.org/en-US/docs/Web/API/Blob

- 296
- 1
- 8
- 23
Another solution depends on the Portlet Concept:
- in ViewController you fire an event ex "downloadFile"
- in Main Controller you catch the event and execute a function "downloadFile" and call a function in let it the same name
AjaxController (Ext.app.Controller) you call the function doStandardSubmit
location.href = this.url + '&operation=download¶m1=' + param1val;
in the Backend of the portlet (Java) you write the endPOint method :
@EndpointMethod(encode = false) public void download(DataAccessor dataAccessor, AuthenticationGenerationConfiguration configuration, @RequestKey String param1, ResourceResponse response) throws IOException {
OutputStream outputStream = response.getPortletOutputStream(); try {
// Adjusting content type response.setContentType("text/plain"); response.setProperty("Content-Disposition", "attachment; filename=\"" + FILENAME + "\""); outputStream.flush(); } finally { outputStream.close(); } }

- 296
- 1
- 8
- 23
-
Does this work to trigger a download on the browser? I found even with content-disposition etc on my project I still had to do some extra stuff to trigger one (would be cool if it did then I can re-examine my project) – Dominic Oct 22 '18 at 18:33
-
no this will trigger the operating system to show the save as dialog. its safe because it does not depend on the browser. I must test it more to enhance it – Hasan Oct 23 '18 at 07:38
-
Yes but in a normal ajax call it won't trigger a download - see https://stackoverflow.com/a/32318930/414062 – Dominic Oct 23 '18 at 08:01
-
the AJAx call will trigger the download function which is written in the portlet. and it will in turn trigger the download. – Hasan Oct 31 '18 at 12:13