JNLP FileSaveService opens a file open dialog
Asked Answered
J

2

8

Hi I'm trying to save a file from a Java Webstart Application.

public class Main {
   public static void main(String[] args) {
      try {
         FileSaveService fos = (FileSaveService) ServiceManager.lookup("javax.jnlp.FileSaveService");
         //open Dialog
         FileContents fc = fos.saveFileDialog("c:/data", null, new ByteArrayInputStream("Hallo Welt".getBytes()), "name.txt");
         System.out.println("FileContents: " + fc);
      } catch (UnavailableServiceException e) {
         System.err.println("***" + e + "***");
      } catch (IOException e) {
         System.err.println("***" + e + "***");
      }
      //wait a minute
      try {
         Thread.sleep(10000);
      } catch (InterruptedException e) {
      }
      System.exit(0);
   }
}

Everything works except that the dialog that comes up looks like a "open" file dialog, not like a "save" file dialog:

FileDialog

Any help would be appreciated.

Jens answered 17/5, 2013 at 12:10 Comment(5)
You might compare your fss.saveFileDialog() parameters to those shown here.Anemochore
I just tried the File Service demo in 1.7.0_21-b11 (Windows 32 bit) and the open & save dialogs appeared as expected. What make & model JRE are the users running?Stieglitz
We're using JRE version 1.6.0_31-b05 Java HotSpot(TM) 64-Bit Server VMJens
I tried the code from trashgods link with the same results. I used this JRE: Java Web Start 10.13.2.20 Using JRE version 1.7.0_13-b20 Java HotSpot(TM) 64-Bit Server VMJens
@AndrewThompson you were right, I should have checked with the newest JDK much earlier...Jens
J
0

This seems to be fixed in JRE bersion 1.7.0_21-b11 Java HotSpot(TM) 64-Bit Server VM

And there it is: https://bugs.java.com/bugdatabase/view_bug?bug_id=2227257

Jens answered 29/5, 2013 at 18:51 Comment(0)
S
1

The File-Open-dialog is necessary. You first need to let the user choose where to save the data. Thus a previous call to openFileDialog is absolute necessary for a jnlp-application. You are not allowed to directly save to a specific location like c:

If you follow the mentioned link (http://docs.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/examples.html#FileSaveService) you should be successful.

EDIT: for clarification. Saving via javax.jnlp.FileSaveService does exactly need one call. For instance calling saveFileDialog() like this should be sufficient:

fss.saveFileDialog(null, null, new ByteArrayInputStream("Hallo Welt".getBytes()    ), "newFileName.txt");

The necessity of one User-Dialogue is due to the anonymizing nature of jnlp, where your application should not get any hint about the user-filesystem. However, I have to admit, that this was not your question.

Your main trouble comes from the java app everytime presenting the "open-dialogue" instead of the "save-dialogue".

This should not happen! If I may humbly assume from your snippet where you call fos.saveFileDialog: did you just initialize fos by the FileOpenService instead of the FileSaveService?

More details on the FileSaveService can be found here: http://docs.oracle.com/javase/7/docs/jre/api/javaws/jnlp/javax/jnlp/FileSaveService.html

Sperling answered 27/5, 2013 at 22:11 Comment(1)
When I run the code in the example in the link, I see 3 times an open dialog. What did you see?Jens
J
0

This seems to be fixed in JRE bersion 1.7.0_21-b11 Java HotSpot(TM) 64-Bit Server VM

And there it is: https://bugs.java.com/bugdatabase/view_bug?bug_id=2227257

Jens answered 29/5, 2013 at 18:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.