2 Replies Latest reply on Jan 31, 2007 5:08 AM by Pete Muir

    Question about request/response lifecycle

    milestone Newbie

      Hi All,

      I have stumbled upon this article: http://today.java.net/pub/a/today/2006/02/09/file-uploads-with-ajax-and-jsf.html and I am trying to get this work with seam. The ProgressBar Component does not work. I think I know why, but I am not sure.

      I noticed that the Author wrote inside his FileUploadRenderer Component

      if(parameterMap.containsKey(PROGRESS_REQUEST_PARAM_NAME))
       {
       // This is a request to get the progress on the file request.
       // Get the progress and render it as XML
      
       HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
      
       // set the header information for the response
       response.setContentType("text/xml");
       response.setHeader("Cache-Control", "no-cache");
      
       try
       {
       ResponseWriter writer = FacesUtils.setupResponseWriter(context);
       writer.startElement("progress", input);
       writer.startElement("percentage", input);
       // writer.writeText(result, null);
       // Get the current progress percentage from the session (as set
       // by the filter).
       Double progressCount = (Double) extContext.getSessionMap().get(
       "FileUpload.Progress." + input.getClientId(context));
      
       if(progressCount != null)
       {
       writer.writeText(progressCount, null);
       }
       else
       {
       // We havn't received the upload yet.
       writer.writeText("1", null);
       }
      
       writer.endElement("percentage");
       writer.startElement("clientId", input);
       writer.writeText(input.getClientId(context), null);
       writer.endElement("clientId");
       writer.endElement("progress");
      
       }
       catch (Exception e)
       {
       // Do some sot of error logging...
       throw new RuntimeException(e);
       }
      
       }
       else
       {
       // Normal decoding request.
       if(requestMap.get(clientId).toString().equals("file"))
       {
       try
       {
       HttpServletRequest request = (HttpServletRequest) extContext.getRequest();
       FileItem fileData = (FileItem) request.getAttribute(clientId);
       if(fileData != null)
       input.setSubmittedValue(fileData);
      
       // Now we need to clear any progress associated with this
       // item.
       extContext.getSessionMap()
       .put("FileUpload.Progress." + input.getClientId(context), new Double(100));
      
       }
       catch (Exception e)
       {
       throw new RuntimeException(
       "Could not handle file upload - please ensure that you have correctly configured the filter.",
       e);
       }
       }
       }
       }
      


      It seems as if the author is trying to itercept the response sent back to the client, by sending a response.setContentType("text/xml");. Is this really possible?

      I rather think, that this has to go inside a PhaseListener, and output the XML from there, or am I wrong?

      Any Help is highly appreciated

      Kind regards

      Juergen