0

Within my JSP page, I have used the following ajax call (valums-file-uploader) and the file is uploaded successfully. The JSF invokes the appropriate Servlet correctly. I am checking the uploaded file and doing Server Side validations within the Servlet. I am not sure how I can print the messages back to the same JSP's div. For example. If a field is empty, The file will not upload but I also want to display a custom message along with it. As of now I have stored the messages in the String format. I have the HttpServletResponse object but not sure how I can pass this custom String back to JSP page.

Thanks for any help or suggestions :)

     new qq.FileUploader({
            element: document.getElementById('file-uploader-demo1'),
            allowedExtension: 'xls|xlsx',
            action: '.....', 
            debug: true,
            onSubmit : function(file, ext){
                // change button text, when user selects file           

            },

            onComplete: function(id, fileName, responseJSON){
                if(!responseJSON.success)
                { //console.log (responseJSON.message); 

                    showErrorBulkOrder();
                }
                else{
                    showSubmitBulkOrder();
                }
            }

        });
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
user1596476
  • 41
  • 1
  • 3
  • If you can, it would be better to use a third party library component to handle file upload that already has built-in compatibility with JSF 2 like [PrimeFaces File Upload](http://www.primefaces.org/showcase/ui/fileUploadMultiple.jsf) or [RichFaces File Upload](http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=fileUpload) components. – Luiggi Mendoza Mar 14 '13 at 04:24
  • Thank you for the alternate suggestions.I might use if I face a road block with this issue. I already spent so much time with the existing component and now I'm just one step away. – user1596476 Mar 14 '13 at 14:27

1 Answers1

0

Here's the approach I've taken. I wanted to list if it may be helpful for anybody facing similar issue:

In the Servlet:

Added the following lines in the post method:

     JSONObject jsonObj = new JSONObject(); 
     if (orders == null || orders.size() == 0){
          jsonObj.put("success",false);
      }else{
         jsonObj.put("success",true);
      }
     response.getWriter().print(jsonObj);
     response.setContentType("text/html");

In this way, I can also add more objects that contains messages from Servlet side.

In the XHTML PAGE: same as above.

user1596476
  • 41
  • 1
  • 3