File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Browsing for file Path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Browsing for file Path" Watch "Browsing for file Path" New topic
Author

Browsing for file Path

Daniel Browne
Greenhorn

Joined: Jul 13, 2011
Posts: 5

Hi,

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?

Thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.
Daniel Browne
Greenhorn

Joined: Jul 13, 2011
Posts: 5

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:
"C:\Users\username\Documents\file.txt"

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.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Daniel Browne wrote:The application saves variable to a text file which can be loaded if the web application is run again.


And how exactly does it do that?
Daniel Browne
Greenhorn

Joined: Jul 13, 2011
Posts: 5

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.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.
Daniel Browne
Greenhorn

Joined: Jul 13, 2011
Posts: 5

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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.
Daniel Browne
Greenhorn

Joined: Jul 13, 2011
Posts: 5

ok, thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Browsing for file Path