Carlos Conti wrote:Hi Tim, thanks for your insisghts.
I preffer to deal with the "folder navigation" inside the backing bean and open the files in a JavaSE fashion, by using absolute paths in the server, instead of writing any relative paths in the url.
I totally don't understand what this means. You make it sound like
JSF beans have some sort of file browsing capability. Unless maybe you're thinking that you can put the copy logic in JSF backing beans.
You can't. JSF will add a lot of HTML-related freight that will make garbage out of any image files, PDF's, and other non-HTML files. You need to do the file copy in a non-JSF HTTP request handler, such as a servlet. Usually file-copy servlets aren't very complicated, however.
Also, the URL is
not a filename path. It just looks like one. The default servlet simply takes advantage of that to make it easier to construct an actual filename path from the parsed URL.
When opening a file in a webapp, it's always a good idea to use an absolute path. In a webapp you never can tell what the current directory may be, and the current directory is the basis for relative paths (relative to the current directory, to be precise!). However, since, like I said, a URL is not a filename path, the file-copy mechanism is totally at liberty to pick whatever absolute basis it wants to. Though picking the root of the file system isn't a good choice, since most OS's have directories full of stuff that are best not made public.
As far as configuring in an absolute base directory, you can hard-code it, put it in a properties file/database record, or use a mechanism such as JNDI. I prefer the JNDI route, since most of the other solutions tend to require keeping separate editions of the app for development,
test, and production. JNDI allows you to supply the value as a deployment descriptor (Context) setting.