Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Carey Brown
  • Frits Walraven

JSF with fileupload and iframe

Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 <h:outputText> 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 <h:outputText> 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
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there Christopher.

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

Basically <h:outputText> 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
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 <h:outputText> 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:


pie. tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
    Bookmark Topic Watch Topic
  • New Topic