Kush Sahu
Kush Sahu

Reputation: 399

Anyway to upload file by ajax in JSF?

I need to upload file ajax so that I can show the name of uploaded file but without adding any jar files like primefaces, richfaces.

My form is inside dialog box where I have an upload button which should call a method by ajax. My code is something like this...

<h:commandButton value="Upload" action="#{bean.uploadMethod}">
<f:ajax listener="#{bean.abcMethod}" event="click"/>
</h:commandButton>

and I would also like to know if I can just browse, keep the name of file in some list to show and then I can submit my whole form. This submission should also upload those files which I have shown the name in list. Is it possible?

Upvotes: 3

Views: 1459

Answers (2)

maple_shaft
maple_shaft

Reputation: 10463

Primefaces offers the FileUpload component which is a fully AJAX enabled file upload JSF component.

Here is the showcase example

I am not complete sure how it works but I believe it utilizes modern browser features through HTML5. This functionality of course requires that the client be a modern browser that can understand HTML5 markup.

Upvotes: 0

siebz0r
siebz0r

Reputation: 20339

I'm also struggling with uploading files (images) through AJAX. I've looked for several methods and how companies like Google or Dropbox implemented this.

So far I found two methods:

  • Use an iframe to submit the file. This isn't actually AJAX, so it works in most browsers. However I have yet to see an implementation (other than PrimeFaces') in JSF.
  • Encode the file client side with base64, send through AJAX and decode on the server side. However I haven't seen an implementation in JSF and I haven't got the time past days to actually cook something up.

If you want a quick solution you can use , (and probably ). But you already said you didn't want to use one of those.

Maybe someone is nice enough to post a real solution here, but I thought I'd throw in an idea or two. ;-)

Upvotes: 2

Related Questions