This is something I've been struggling with for a couple months now without having much luck. I beginning to think it's not possible but I'm hoping someone here can prove me wrong.

The environment I am working with is a JSP page that interfaces with a java Bean.

I want the JSP page to allow the user to browse for files and then for each file selected, add it to a list in the java Bean. The problem is once the user finds the file, I can't figure out how to pass that filename to the Bean.

It works just fine if instead of browsing for the file, I just have the user type in the file name as in the example code below.

<h:inputText value="#{fileItemController.fileItem.pathname}" required="true">
<h:commandButton action="#{fileItemController.save}" value="Save"

In this example, the save method of the fileItemController Bean knows about text that was typed in (pathname) and it adds it to the list. The problem with this is it is tedious for the user to type in the entire path name each time and it opens up the possibility for a typo.

Instead, I want the user to browse for the file rather than typing in the pathname. For this, I tried using the html input tag as follows:

<input type="file" name="file_name" />

I verified that "file_name" does contain the name of the file that was browsed, however, I can't figure out how to let the Bean know about it. I've tried replacing "file_name" with "#{fileItemController.fileItem.pathname}" but that doesn't work. If I do that, I get an "#{..} is not allowed in template text" error message.

Any thoughts or ideas will be greatly appreciated.

7 Years
Discussion Span
Last Post by adabq
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.