You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by csckid <te...@gmail.com> on 2012/01/14 13:41:37 UTC

streamresponse and redirect

I have submit button named savePrescription. What I want is when this button
is clicked it would save the data then return the pdf file via stream
response and redirect to a page. 
So far I was able to save the data and return the pdf in target="_blank" but
I don't know how would I redirect the existing page into another page.


I tried the following: this redirects but doesn't open the stream response.
StreamResponse onSuccessFromSavePrescription() {
                        //savedata
                        response.sendRedirect("index");
			InputStream is = prescriptionPdf.pdfGeneration(patient, visit);
			return new PDFStreamResponse(is,"Prescription-"+visit.getId());
			
}

--
View this message in context: http://tapestry.1045711.n5.nabble.com/streamresponse-and-redirect-tp5144924p5144924.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: streamresponse and redirect

Posted by Christian Köberl <ta...@gmail.com>.
2012-01-14 13:41, csckid:
> I have submit button named savePrescription. What I want is when this button
> is clicked it would save the data then return the pdf file via stream
> response and redirect to a page. 
> So far I was able to save the data and return the pdf in target="_blank" but
> I don't know how would I redirect the existing page into another page.
> 
> 
> I tried the following: this redirects but doesn't open the stream response.
> StreamResponse onSuccessFromSavePrescription() {
>                         //savedata
>                         response.sendRedirect("index");
> 			InputStream is = prescriptionPdf.pdfGeneration(patient, visit);
> 			return new PDFStreamResponse(is,"Prescription-"+visit.getId());
> 			
> }

You cannot send a PDF and a HTML page in one HTTP response.

What you have to do is send a page containing a JS that opens a browser
window with the link to the PDF.

Object onSuccessFromSavePrescription() {
  // savedata
  return AnotherPage.class;
}

In AnotherPage:

void beforeRender() {
  String linkUrl = componentResources
    .createEventLink("showPdf").toURI();
  jsSupport.addScript("window.open('%s')", linkUrl);
}

StreamResponse onShowPdf() {
  InputStream is = prescriptionPdf.pdfGeneration(patient, visit);
  return new PDFStreamResponse(is,"Prescription-"+visit.getId());
}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org