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="#{}" 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.

After doing some deeper digging on the subject, I found the answer to this. This can be accomplished with the utilization of third party components. Specifically for this, I used the Apache tomahawk library tag and commons fileupload. Rather than explain in detail here what I did, I basically followed the tutorial on this link:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.