aspose file tools*
The moose likes JSF and the fly likes Updating page when uploading files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Updating page when uploading files" Watch "Updating page when uploading files" New topic
Author

Updating page when uploading files

Christopher Sharp
Ranch Hand

Joined: Dec 12, 2007
Posts: 155
Hello Ranchers,

I have a question about how to update a page when files are uploaded. I got the basic code using PrimeFaces and the <p:fileUpload> tag to work straight away from the example given at:

http://www.mastertheboss.com/primefaces/primefaces-file-upload-example

after putting the PrimeFaces jar file in my WEB-INF\lib folder in Eclipse, together with two other jars necessary for uploading, and adding the neccesary code to the web.xml file.

What I want to do is display on the screen a list of files that have been uploaded, together with a message for each file indicating whether it has been successfuly uploaded or not, but I do not know how to get the screen to automatically refreshed on each file upload, and have added a button to do this manually, which is not very satisfactory.

The xhtml code is as follows:

The idea is that you click the choose button generated by PrimeFaces, then select a file to upload, then upload it. This part works correctly, but what I want is the list displayed to be updated, first with the first file uploaded, followed by the second, and so on, and in each case a message is displayed to the right of that file. However, at the moment I have to click the Refresh button which fires an action event that does this.

This is based on some original code I wrote a while ago that uses other software for uploading files, and the display was generated entirely by JavaScript, and I want to keep most of the basic appearance similar.

The java code is as follows:

On specifying the number of files you want to upload then clicking the "Update" button, a table is displayed with the first columns as "File 1", "File 2", "File 3", etc., to the right of that is a blank column, and to the right the characters "XXXX" are currently displayed as a place holder. On each file upload the file name is placed in the middle column, and "XXXX" is replaced by an appropriate message.

The code needs to be tidied up and some changes have to be made anyway, but in the first instance I would like to know how to update this table directly on each file upload, without having to fire an action event using the "Refresh" button, which I want to remove. The ArrayList holding boolean values will eventually be used to keep track of those files that have been successfuly uploaded, for which the user need take no further action.

I would be most grateful for some advice on this.

Christopher Sharp>
Christopher Sharp
Ranch Hand

Joined: Dec 12, 2007
Posts: 155
Shortly after posting this I found a solution. You give a name to the update attribute in the <p:fileUpload> tag which references the id of the <p:dataTable> tag. In my case I used update="fileTable", then id="fileTable" in the dataTable tag, and it works.
 
Don't get me started about those stupid light bulbs.
 
subject: Updating page when uploading files