1

In the widely well-discussed subject of file uploading, there is an aspect that I am missing. I have a JSF 2.2 application that uploads files via HTML5 exactly as shown here. It basically uses HTML5 apis to upload multiple files and then the JS calls a Servlet to write them on disk (the Servlet is called once per file, so no multiple Part treatment is necessary). Now I want to enable <input type=file> in the same element. This in isolation could be done exactly as shown here (although perhaps the solution needs some tweak for multiple files, not sure if this latter information is obsolete).

My question is, I obviously want to code the file writing only once, not one in the Servlet and another in the Managed Bean:

  • Should I do all writing in the Servlet? If so, how should I post the parts to the Servlet from the managed bean? (I am new to JSF)
  • OR should I do all writing in the Managed bean, by calling the Managed Bean save() method from my D&D javascript? If so, I will change this line xhr.open("POST", "uploadServlet", true) to something else, but I am not sure how to make the call and pass the parts.

As an aside note, now that JSF is freeing me from doing all sort of tedious stuff, I am not totally sure what the role of Servlets is. One more detail I should point is that, in future, I might want to mirror Web functionality in Web Services. Perhaps that will impact this answer and the way I should deal with JSF - meaning that I should do all functionality in Servlets and call them from both JSF and Web Services, instead of doing the functionality in the Managed Bean itself.


EDIT

Still working on the problem. I am trying to get rid of the Servlet and use a method in the managed bean. However, I have no idea how I could submit the POST data to the managed bean. SO I have these in my external JS file:

xhr.open("POST", "uploadServlet, true);
xhr.send(formData);

And I should redirect it to the method. This is another way I could solve my problem but still some unknowns, how could I pass the POST to the method?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user1156544
  • 1,725
  • 2
  • 25
  • 51

0 Answers0