[jboss-user] [JBoss Seam] - Re: Progress bar for fileUpload

zaya do-not-reply at jboss.com
Tue Oct 23 22:18:17 EDT 2007


A temporary solution:

Overide multipartFilter to put multipartRequest into session(Put this class anywhere in application source):

  | @Startup
  | @Scope(APPLICATION)
  | @Name("org.jboss.seam.web.multipartFilter")
  | @Install(precedence = Install.APPLICATION)
  | @BypassInterceptors
  | @Filter(within={"org.jboss.seam.web.ajax4jsfFilter", "org.jboss.seam.web.exceptionFilter"})
  | public class MonitoredMultipartFilter extends MultipartFilter {
  |     
  |     @Override
  |     public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
  |     throws IOException, ServletException {
  | 	if (!(response instanceof HttpServletResponse)) {
  | 	    chain.doFilter(request, response);
  | 	    return;
  | 	}
  | 	
  | 	final HttpServletRequest httpRequest = (HttpServletRequest) request;
  | 	
  | 	if (isMultipartRequest(httpRequest)) {
  | 		processMultipart(httpRequest, response, chain);
  | 	} else chain.doFilter(request, response);
  |     }
  |     
  |     private void processMultipart(HttpServletRequest httpRequest, ServletResponse response, FilterChain chain)
  |     throws IOException, ServletException {
  | 	
  | 	MultipartRequest multipartRequest = new MultipartRequest(httpRequest, getCreateTempFiles(), getMaxRequestSize());
  | 	HttpSession httpSession = httpRequest.getSession(false);
  | 	if (httpSession != null) {
  | 	    httpSession.setAttribute("MULITIPART_REQUESET", multipartRequest);
  | 	}
  | 	
  | 	chain.doFilter(multipartRequest, response);
  | 	
  |     }
  |     
  |     private boolean isMultipartRequest(HttpServletRequest request) {
  | 	if (!"post".equals(request.getMethod().toLowerCase())) {
  | 	    return false;
  | 	}
  | 	
  | 	String contentType = request.getContentType();
  | 	if (contentType == null) {
  | 	    return false;
  | 	}
  | 	
  | 	if (contentType.toLowerCase().startsWith(MULTIPART)) {
  | 	    return true;
  | 	}
  | 	
  | 	return false;
  |     }
  | }
  | 

And in the backing seam component:

  |     @In(value="MULITIPART_REQUESET",required=false)	private MultipartRequest multipartRequest;
  |     private static final String UPLOAD_COMPONENT_ID_IN_HTML = "uploadForm:upload";
  | 
  |     @WebRemote
  |     public Integer uploadPercentage() {
  | 	int uploadsize = multipartRequest.getFileSize(UPLOAD_COMPONENT_ID_IN_HTML);
  | 	int totalsize = multipartRequest.getContentLength();
  | 	if (uploadsize>=0 && totalsize>=0) {
  | 	    Integer progress = (int)Math.floor(((double)uploadsize / (double) totalsize) * 100.0);
  | 	    return progress;
  | 	} else return null;
  |     }
  | 

Now seam remoting can access uploadPercentage() method to get the progress.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4098102#4098102

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4098102



More information about the jboss-user mailing list