[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

jsf richfaces file download within backingbean method not working as it should

Asked by mathewstcom in Java Server Faces (JSF)

Tags: jsf richfaces file download

hi i need to download pdf file from jsf richfaces application
following is my code but it doesnt initiate download but it ll write content of pdf into page, ofc not proporely its writing there binary data of pdf not proper content
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
		HttpServletResponse resp = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
		resp.reset();
		String offerId = req.getParameter("id");
		Long id = new Long(offerId);
		Dokument dokument = dokumentSvc.findLoaded(id);
		
		String contentType = TypDokumentu.PDF == dokument.getTyp()?"application/pdf":"text/html";
		String extension = TypDokumentu.PDF == dokument.getTyp()?".pdf":".html";
		
		try {
			if (dokument == null)
				showNA(resp);
			else {
				resp.setContentType("application/force-download");
				resp.setContentLength(dokument.getData().getData().length);
				resp.setHeader("Content-Disposition",
						"download; filename=\"preview.pdf\"");
	
				OutputStream ou;
				ou = resp.getOutputStream();
				ou.write(dokument.getData().getData());
				ou.flush();
				ou.close();
			}
		} catch(Exception e) { 
		}
		
		FacesContext.getCurrentInstance().responseComplete();
[+][-]10/21/09 02:26 AM, ID: 25622080Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/21/09 03:30 AM, ID: 25622429Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93 - Hierarchy / EE_QW_3_20080625