You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by tapestryphoto <ph...@digiatlas.org> on 2008/12/15 14:45:06 UTC

[T5]: query regarding streaming data

Hi,

possibly not Tapestry specific and I'm not knowledgable enough on this  
subject, so apologies.

I would like to be able to display a PDF that I obtain from a database  
using Hibernate via Tapestry. Is there a way to stream the data?

thanks,
p.




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


Re: [T5]: query regarding streaming data

Posted by tapestryphoto <ph...@digiatlas.org>.
Thanks Julian - that did the trick.  Much appreciated.

p.


Quoting Julian Wood <wo...@ucalgary.ca>:

> It works fine.
>
> Try something like this:
>
> public class TestPage {
>     public Object onPDF(Long id) {
>         return new PDFStreamResponse(dao.getPDF(id));
>     }
>
>     public Link getPDFLink() {
>         return resources.createActionLink("pdf", false);
>     }
> }
>
> public class PDFStreamResponse implements StreamResponse {
>     byte[] pdf;
>
>     public PDFStreamResponse(byte[] pdf) {
>         this.pdf = pdf;
>     }
>
>     public String getContentType() {
>         return "application/pdf";
>     }
>
>     public InputStream getStream() throws IOException {
>         return new ByteArrayInputStream(pdf);
>     }
>
>     public void prepareResponse(Response response) {
>     }
> }
>
> TestPage.tml:
> <a href="javascript:openPdf('${pdfLink}')">Open a PDF</a>
>
> J
>
>
> On Dec 15, 2008, at 7:59 AM, tapestryphoto wrote:
>
>> Thanks Olle,
>>
>> However, reading the docs I see that the Streaming applies to   
>> components. In my situation I need to open a new window, which I   
>> currently do with JavaScript (in this example I'm obviously opening  
>>  a local file, but as I said, in the real version it needs to come   
>> from the DB):
>>
>> e.g.:
>>
>> <p><a href="javascript:openPdf('file:///c:/DMR2008.pdf')">Open a PDF</a></p>
>>
>>
>> which is so I can auto-close the window:
>>
>>
>> function openPdf(url)
>> {
>> 	windowprops = "left=10,top=10,width=1000,height=1100";
>>
>> 	if (ChildWin)
>> 	{
>> 		return false;
>> 	}
>>
>> 	ChildWin = window.open(url, "ChildWin", windowprops);
>> 	ResetTimer();
>>
>> 	if (TimeOut && RefreshRate)
>> 	{
>> 		setTimeout("CheckClose();",RefreshRate * 1000);
>> 	}
>> }
>>
>>
>> I really need the streaming to be coming from a URL I am opening   
>> and as far as I can see that won't work as StreamResponse applies   
>> to Components only.
>>
>> Hmmm.....  !
>>
>> p.
>>
>>
>> Quoting Olle Hallin <ol...@gmail.com>:
>>
>>> Yes, there is.
>>>
>>> Let your handler method return a StreamResponse object.
>>>
>>> See http://tapestry.apache.org/tapestry5/guide/pagenav.html
>>> and
>>> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/StreamResponse.html.
>>>
>>> Olle
>>>
>>>
>>> 2008/12/15 tapestryphoto <ph...@digiatlas.org>
>>>
>>>> Hi,
>>>>
>>>> possibly not Tapestry specific and I'm not knowledgable enough on this
>>>> subject, so apologies.
>>>>
>>>> I would like to be able to display a PDF that I obtain from a database
>>>> using Hibernate via Tapestry. Is there a way to stream the data?
>>>>
>>>> thanks,
>>>> p.
>>>>
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>
>>>>
>>>
>>>
>>> --
>>> Olle Hallin
>>> Senior Java Developer and Architect
>>> olle.hallin@crisp.se
>>> www.crisp.se
>>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org




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


Re: [T5]: query regarding streaming data

Posted by Julian Wood <wo...@ucalgary.ca>.
It works fine.

Try something like this:

public class TestPage {
     public Object onPDF(Long id) {
         return new PDFStreamResponse(dao.getPDF(id));
     }

     public Link getPDFLink() {
         return resources.createActionLink("pdf", false);
     }
}

public class PDFStreamResponse implements StreamResponse {
     byte[] pdf;

     public PDFStreamResponse(byte[] pdf) {
         this.pdf = pdf;
     }

     public String getContentType() {
         return "application/pdf";
     }

     public InputStream getStream() throws IOException {
         return new ByteArrayInputStream(pdf);
     }

     public void prepareResponse(Response response) {
     }
}

TestPage.tml:
<a href="javascript:openPdf('${pdfLink}')">Open a PDF</a>

J


On Dec 15, 2008, at 7:59 AM, tapestryphoto wrote:

> Thanks Olle,
>
> However, reading the docs I see that the Streaming applies to  
> components. In my situation I need to open a new window, which I  
> currently do with JavaScript (in this example I'm obviously opening  
> a local file, but as I said, in the real version it needs to come  
> from the DB):
>
> e.g.:
>
> <p><a href="javascript:openPdf('file:///c:/DMR2008.pdf')">Open a  
> PDF</a></p>
>
>
> which is so I can auto-close the window:
>
>
> function openPdf(url)
> {
> 	windowprops = "left=10,top=10,width=1000,height=1100";
>
> 	if (ChildWin)
> 	{
> 		return false;
> 	}
>
> 	ChildWin = window.open(url, "ChildWin", windowprops);
> 	ResetTimer();
>
> 	if (TimeOut && RefreshRate)
> 	{
> 		setTimeout("CheckClose();",RefreshRate * 1000);
> 	}
> }
>
>
> I really need the streaming to be coming from a URL I am opening and  
> as far as I can see that won't work as StreamResponse applies to  
> Components only.
>
> Hmmm.....  !
>
> p.
>
>
> Quoting Olle Hallin <ol...@gmail.com>:
>
>> Yes, there is.
>>
>> Let your handler method return a StreamResponse object.
>>
>> See http://tapestry.apache.org/tapestry5/guide/pagenav.html
>> and
>> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/StreamResponse.html 
>> .
>>
>> Olle
>>
>>
>> 2008/12/15 tapestryphoto <ph...@digiatlas.org>
>>
>>> Hi,
>>>
>>> possibly not Tapestry specific and I'm not knowledgable enough on  
>>> this
>>> subject, so apologies.
>>>
>>> I would like to be able to display a PDF that I obtain from a  
>>> database
>>> using Hibernate via Tapestry. Is there a way to stream the data?
>>>
>>> thanks,
>>> p.
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>
>>
>> --
>> Olle Hallin
>> Senior Java Developer and Architect
>> olle.hallin@crisp.se
>> www.crisp.se
>>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


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


Re: [T5]: query regarding streaming data

Posted by tapestryphoto <ph...@digiatlas.org>.
Thanks Olle,

However, reading the docs I see that the Streaming applies to  
components. In my situation I need to open a new window, which I  
currently do with JavaScript (in this example I'm obviously opening a  
local file, but as I said, in the real version it needs to come from  
the DB):

e.g.:

<p><a href="javascript:openPdf('file:///c:/DMR2008.pdf')">Open a PDF</a></p>


which is so I can auto-close the window:


function openPdf(url)
{
	windowprops = "left=10,top=10,width=1000,height=1100";

  	if (ChildWin)
	{
		return false;
	}

	ChildWin = window.open(url, "ChildWin", windowprops);
	ResetTimer();

	if (TimeOut && RefreshRate)
	{
		setTimeout("CheckClose();",RefreshRate * 1000);
	}
}


I really need the streaming to be coming from a URL I am opening and  
as far as I can see that won't work as StreamResponse applies to  
Components only.

Hmmm.....  !

p.


Quoting Olle Hallin <ol...@gmail.com>:

> Yes, there is.
>
> Let your handler method return a StreamResponse object.
>
> See http://tapestry.apache.org/tapestry5/guide/pagenav.html
> and
> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/StreamResponse.html.
>
> Olle
>
>
> 2008/12/15 tapestryphoto <ph...@digiatlas.org>
>
>> Hi,
>>
>> possibly not Tapestry specific and I'm not knowledgable enough on this
>> subject, so apologies.
>>
>> I would like to be able to display a PDF that I obtain from a database
>> using Hibernate via Tapestry. Is there a way to stream the data?
>>
>> thanks,
>> p.
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
> --
> Olle Hallin
> Senior Java Developer and Architect
> olle.hallin@crisp.se
> www.crisp.se
>




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


Re: [T5]: query regarding streaming data

Posted by Olle Hallin <ol...@gmail.com>.
Yes, there is.

Let your handler method return a StreamResponse object.

See http://tapestry.apache.org/tapestry5/guide/pagenav.html
and
http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/StreamResponse.html.

Olle


2008/12/15 tapestryphoto <ph...@digiatlas.org>

> Hi,
>
> possibly not Tapestry specific and I'm not knowledgable enough on this
> subject, so apologies.
>
> I would like to be able to display a PDF that I obtain from a database
> using Hibernate via Tapestry. Is there a way to stream the data?
>
> thanks,
> p.
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Olle Hallin
Senior Java Developer and Architect
olle.hallin@crisp.se
www.crisp.se