I'm trying to create a web application in JSF which allows the users to save and
load to a text file. I would like to provide the "open" and "save as" functions
similar to those found in word documents so that the file path can be found and
added as a String. Is this possible and how would you go about achieving it?
It isn't possible for web applications to interact with the client's file system. If that's what you meant. It might be possible for your application to implement a virtual file system using files on the server, but I don't know if that was your question.
Sorry, I'll see if I can't explain what I'm trying to do a bit better.
The application saves variable to a text file which can be loaded if the web application is run again. The problem is that the user has to specify the complete file path such as:
So I was hoping there would be something available similar to the "save as" function found in word so that the user can specify where on their computer they wish to save the text file making it easier for them to find the file when loading it again.
I added a function in the bean that writes all the required variables to a text file. Then when it comes to loading the file again I have another function that loads the variables in the correct order and reproduces the end result of the application that was saved.
Ah. So that answers my question: you are saving the data to a file on the server, not to a file on the client's machine.
So yeah, presumably you could write something in JSF which uses some beans to allow the user to choose a location on your server. You're going to want to put some restrictions on exactly where they can save, you don't want people fishing through your server and trampling on files which ought to be left alone.
Or better still, don't give them the choice at all. Make them save in a specific directory on your folder. This prevents the security exposure you would get by allowing the user to choose a folder and as a bonus it makes your requirement go away.
I'm not sure, I was trying to design it so that the user could save it to on their own computer, and load it from whereever they may have saved it.
I tried creating a file to hold the text files being generated but unless I specified the complete file path it doesn't work and I can't program that into the bean as when I move the program from one computer to another the file path changes.
Paul Clapham wrote:It isn't possible for web applications to interact with the client's file system.
Although that isn't quite correct. If you use trusted components, like for example a signed applet, then they can. But in general you don't want to connect to a web application and find it has access to everything on your computer. You really don't. Think about it in the context of security.