Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Download file (PDF) and open on a new tab

andiNov 8 2012 — edited Nov 8 2012
Hi All,

Jdeveloper version: 11.1.2.1.0

Use Case:
When user press the command button, system should retrieve PDF document from the database (BLOB file) and display on a new tab

Problem:
Managed to retrieve the file, but it replaces the current page rather than opening a new tab
I've tried few suggestions from below link, but still no luck:
- 2432385
- https://kr.forums.oracle.com/forums/thread.jspa?threadID=637676

My Code:
==============================================================
BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();

+// get an ADF attributevalue from the ADF page definitions+
AttributeBinding attr = (AttributeBinding) bindings.getControlBinding("DsgnFileData");
if (attr == null)
+{+
return;
+}+

+// the value is a BlobDomain data type+
BlobDomain blob = (BlobDomain) attr.getInputValue();

try
+{+
ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
HttpServletResponse response = (HttpServletResponse)ectx.getResponse();
ServletOutputStream out = response.getOutputStream();
response.setHeader("Cache-Control", "max-age=0");
response.setHeader("Content-Disposition", "inline; filename=Report.pdf");
response.setContentType("application/pdf");

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
IOUtils.copy(blob.getInputStream(), byteArrayOutputStream);

out.write(byteArrayOutputStream.toByteArray());
out.flush();
out.close();
FacesContext.getCurrentInstance().responseComplete();
+}+
catch (IOException e)
+{+
+// handle errors+
e.printStackTrace();
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), "");
FacesContext.getCurrentInstance().addMessage(null, msg);
+}+
==============================================================

Has anyone managed to do this? Help please
Thank you


Regards,
Andi
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 6 2012
Added on Nov 8 2012
3 comments
4,926 views