File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes JSF with fileupload and iframe Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF with fileupload and iframe" Watch "JSF with fileupload and iframe" New topic

JSF with fileupload and iframe

Christopher Sharp
Ranch Hand

Joined: Dec 12, 2007
Posts: 152
Regarding my recent postings on the JSF file upload thread, what I've done now is to incorporate a modified version of that in my main application. But in order to make as few changes as possible to earlier code, I'm using an iframe to display the file upload page in an existing page of my application.

What I need to do is that if a file is successfully uploaded, I want to use JavaScript to pass its name on to the page containing the iframe. In the file upload page I have the following code:

where I have modified my bean from the file upload thread to include a getFilename() method which is displayed here. Without the JavaScript, this works fine, and as a test the filename is printed below the message that the file has been successfully uploaded.

However, if I put in onchange="getFilename()" in the <hutputText> tag together with the JavaScript as shown here, I get an Http 500 error message together with the following message in the server log:

Servlet.service() for servlet jsp threw exception org.apache.jasper.JasperException: /upload/uploadfile.jsp(26,4) PWC6131: Attribute onchange invalid for tag outputText according to TLD at org.apache.jasper.compiler.DefaultErrorHandler.jspError( at org.apache.jasper.compiler.ErrorDispatcher.dispatch( at org.apache.jasper.compiler.ErrorDispatcher.jspError(

What does "onchange invalid for tag outputText according to TLD" mean?

However, if I remove the onchange="getFilename()" in the <hutputText> tag as displayed and instead put in onklick="getFilename()" in the <h:commandButton> tag and replace:


in the JavaScript, it works and returns the full path to the file as well as the filename. Why does this work but the onchange does not.

The code that works is not particularly useful, as it gives the filename together with its path before it is uploaded, whereas it would be much more useful to have just the filename after it has been successfully uploaded.

Assuming this can be fixed, then the alert() in the JavaScript will have to be replaced by some code that writes the filename to the appropriate location in the parent page with the iframe.

Some help from Darryl or anybody else would be most appreciated to solve this interesting problem.

I have used "onklick()" as the spelling because of the way the text is parsed.

Christopher Sharp
Darryl Nortje
Ranch Hand

Joined: Jun 11, 2002
Posts: 140
Hi there Christopher.

"What does "onchange invalid for tag outputText according to TLD" mean?"

Basically <hutputText> renders as text in the html. You can't really have any onChange events on text in html. Unlike a drop down box, or input field for example. So, it's like trying to call a method on a class where that method is not defined. There is no onChange "method" defined in the tag library descriptor.

Also with regards to the javascript printing out the filename on the client side. Javascript runs on the client side. So it will print the file name. If you want the filename on the server side then you must get it from the bean. So I would put the logic to figure out just the filename, in the bean's getFileName() method, and then call that by way of EL. eg:

Christopher Sharp
Ranch Hand

Joined: Dec 12, 2007
Posts: 152
Hi Darryl,

OK, many thanks indeed for that helpful advice, as it's saved me a lot of time. I've now altered the code to the following:

where on clicking the "Load the file" button the file is uploaded as before and its name is also displayed as before, but in addition I store its name in <h:inputHidden>, which is read by JavaScript and displayed by the alert() function when the next file is uploaded. The alert() function skips a null filename, as there will be no previous filename on the first upload.

Eventually the idea is to replace alert() by a means of putting the filename in the parent page that holds the iframe tag. As this is in the middle of a file controlled by JavaScript, I'm likely to mess up the code by putting JSF tags in it.

I noticed that I was unable to pick up the filename with JavaScript if I just tried to read it from the <hutputText> tag, so had to include the <h:inputHidden> tag, then add a setter bean for that.

However, eventually it might be much better to update the parent page immediately after a file is successfully uploaded, but this might mean getting involved with AJAX or whatever.

Incidentally, at is an earlier version of the page that will have the iframe, and the relevant code is provisionally:


I agree. Here's the link:
subject: JSF with fileupload and iframe